fork(1) download
  1. #include <iostream>
  2. int main()
  3. {
  4. using namespace std;
  5. int ctr = 0, i = 42, tmp = 0;
  6. while (cin >> i)
  7. {
  8. if (i == 42 && tmp != 42) ctr++;
  9. else if (i == 42 && tmp == 42) ctr--;
  10. if (ctr < 0) ctr = 0;
  11. cout << i << endl;
  12. if (ctr >= 3) break;
  13. tmp = i;
  14. }
  15. return 0;
  16. }
Success #stdin #stdout 0s 5524KB
stdin
42
42
12
13
42
11
42
43
42
42
99
01
stdout
42
42
12
13
42
11
42
43
42