fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. string s="xyxxy";
  7. int n=s.size();
  8. int d[n];
  9. for(int i=0;i<n;i++){
  10. if(s[i]=='x'){
  11. d[i]=-1;
  12. }
  13. else if(s[i]=='y'){
  14. d[i]=1;
  15. }
  16. }
  17. for(int i=0;i<n;i++){
  18. cout<<d[i];
  19. }
  20. unordered_map<int,int>count;
  21. count[0]=1;
  22. int f_count=0;
  23. int sum=0;
  24. for(int i=0;i<n;i++){
  25. sum+=d[i];
  26. if(count.find(sum)!=count.end()){
  27. f_count++;
  28. }
  29. count[sum]++;
  30. }
  31. cout<<f_count;
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
-11-1-113