fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int calc(vector<int> a){
  6. bool countZero = 0;
  7. for (int z : a){
  8.  
  9. if(z){
  10. if (countZero)
  11. cout << 0;
  12. countZero = 0;
  13. cout << 1;
  14. } else {
  15. countZero ^=1;
  16. if (!countZero)
  17. cout << 1;
  18. }
  19. }
  20. if (countZero)
  21. cout << 0;
  22. cout << endl;
  23. }
  24.  
  25. int main() {
  26. calc({1,1,1,1,1,1,1,1});
  27. calc({1,1,1,1,1,1,1,0});
  28. calc({1,0,0,1,1,1,1,1});
  29. calc({1,0,1,0,1,0,1,0});
  30. calc({0,1,0,1,0,1,0,1});
  31. calc({0,0,0,0,0,0,0,0});
  32. calc({0,0,0,1,0,0,0,0});
  33. return 0;
  34. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
11111111
11111110
1111111
10101010
01010101
1111
10111