Challenge: Unique Visitors

Lab C++ Beginner 10 points

Read n and then n numbers (visitor IDs). Print how many different IDs there were, then all the different IDs in increasing order on one line.

Input

n, then n integers.

Output

3
4 7 9

Example

Input

5
9 4 7 4 9

Output

3
4 7 9
Sample input available Sample output available
Editor
C++

Hints

Insert everything into a set<int>: duplicates disappear.

A set loops in increasing order.

Solution explanation

A set removes duplicates and sorts the values for you.

Show solution
#include <iostream>
#include <set>
using namespace std;

int main() {
    int n;
    cin >> n;
    set<int> ids;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ids.insert(x);
    }
    cout << ids.size() << "\n";
    bool first = true;
    for (int id : ids) {
        if (!first) cout << " ";
        cout << id;
        first = false;
    }
    cout << "\n";
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD