//Idea: given array with duplicates (or not) print out duplicate numbers #include #include #include #include using namespace std; #define FOR(i,n) for (int i=0;i<(int)n;i++) #define FORN(i,a,b) for (int i=a;i<=(int)b;i++) int main() { int n; vector v,r; while (cin>>n && n!=0) { v.clear(); r.clear(); v.resize(n); FOR(i,n) cin>>v[i]; sort(v.begin(),v.end()); //sort! int prev=0; FOR(i,v.size()-1) { if (v[i]==v[i+1]) { //first time duplicate is detected //and we record it in "prev" prev=v[i]; } else { //no more duplicates are detected! if (prev>0) //if there was a duplicate, we store it { r.push_back(prev); prev=0; //and reset, so we don't add it again } } } //check if any unrecorded duplicates got left over //i.e. last two numbers in array were the same //so we could not get to them in the loop above if (prev>0) //for previous duplicate { r.push_back(prev); } if (r.size()>0) { cout<