fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main(void)
  7. {
  8. vector <int> arr;
  9.  
  10. int t;
  11. cin >> t;
  12. while (t--)
  13. {
  14. int n;
  15. cin >> n;
  16.  
  17. if (n == 0)
  18. arr.pop_back();
  19. else
  20. arr.push_back(n);
  21. }
  22. int sum = 0;
  23. for (int i = 0; i < arr.size(); i++)
  24. sum += arr[i];
  25. cout << sum;
  26. }
Success #stdin #stdout 0s 5676KB
stdin
4
3
0
4
0
stdout
Standard output is empty