fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. string s="xyxxy";
  7. int f_count=0;
  8.  
  9. for(int i=0;i<s.size();i++){
  10. int cx=0,cy=0;
  11. for(int j=i;j<s.size();j++){
  12. if(s[j]=='x'){
  13. cx++;
  14. }
  15. else if(s[j]=='y'){
  16. cy++;
  17. }
  18. if(cx==cy){
  19. f_count++;
  20. }
  21. }
  22. }
  23. cout<<f_count;
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
4