The basic idea:
Typical hash hash;
key point:
Enter the question:
Here related to the input line number and EOF input, need to take note;
This problem can take advantage of EOF input, but the example has a new idea input line number, take note;
After the digital read using cin, may be utilized cin.get () to determine the problem space, carriage return, to judge, according to a judgment to identify new lines;
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> using namespace std; using std::vector; const int maxn = 100200; int ar[maxn]; int main(){ fill(ar, ar + maxn, 0); int n; cin >> n; getchar(); int min=maxn; int max=-1; for (int i = 0; i < n; i++) { int a; //cout << 111 << endl; while (cin>>a){ if (min > a) min = a; if (max < a) max = a; ar[a] ++; char c = cin.get(); if (c == '\n') break; } } int ansa, ansb; for (int i = min; i <= max; i++) { if (ar[i] == 0) ansa = i; if (ar[i] == 2) ansb = i; } cout << ansa << " " << ansb; }