fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. int X = 0; // Initialize a variable to hold the value
  8.  
  9. while (n--) {
  10. string z;
  11. cin >> z;
  12.  
  13. if (z == "++X" || z == "X++") {
  14. n += 1; // Increment X
  15. }
  16. else if (z == "X--" || z == "--X") {
  17. n -= 1; // Decrement X
  18. }
  19. }
  20.  
  21. cout << X << endl; // Print the final value of X
  22. return 0; // Indicate successful execution
  23. }
  24.  
Success #stdin #stdout 0s 5284KB
stdin
1
x++
stdout
0