fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. int a, b;
  8. vector<int> Alist, Blist;
  9.  
  10. while (cin >> a >> b) {
  11. Alist.insert(Alist.end(), a);
  12. Blist.insert(Blist.end(), b);
  13. }
  14.  
  15. for (int i = 0; i < Alist.size(); i++) {
  16. int g = Alist[i];
  17. int h = Blist[i];
  18. if (h>=g)
  19. for (int y = i+1; y < Blist.size() && Alist[y]<=h; ) { // start with next, stop if over target
  20. if (Alist[y] == h && Blist[y] == g) {
  21. Alist.erase(Alist.begin() + y);
  22. Blist.erase(Blist.begin() + y);
  23. cout << "found "<<h<<" "<<g<<endl;
  24. }
  25. else y++; // move to next only if current one was not erased
  26. }
  27. }
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 3464KB
stdin
1     6
1     4
2     4
2     7
2     5
2     3
3     9
3     2
3     5
4     1
4     6
5     3
5     2
5     8
5     9
6     4
6     1
7     2
8     5
8     9
9     3
9     5
9     8
stdout
found 6 1
found 4 1
found 7 2
found 5 2
found 3 2
found 9 3
found 5 3
found 6 4
found 8 5
found 9 5
found 9 8