fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int count = 0;
  7. vector<char> arr = {'x', 'y', 'x', 'x', 'y', 'x', 'y', 'y'};
  8. int n = arr.size();
  9.  
  10. for(int i = 0; i < n; i++) {
  11. int x_count = 0;
  12. int y_count = 0;
  13. for(int j = i; j < n; j++) {
  14. if(arr[j] == 'x')
  15. x_count++;
  16. else
  17. y_count++;
  18.  
  19. if(x_count == y_count)
  20. count++;
  21. }
  22. }
  23.  
  24. cout << count << endl;
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
10