#include <iostream> #include <vector> #include <string> #include <cstring> using namespace std; int main() { string s; cin >> s; int n = 0; for(int i = 0; i < s.length(); i++){ int a = 0; int b = 0; int c = 0; for(int j = i; j < s.length(); j++){ if(s[j] == 'a') a++; if(s[j] == 'b') b++; if(s[j] == 'c') c++; if( (a==b || a==0 || b == 0) && (a==c || c == 0 || a == 0) && (c == b || b == 0 || c == 0) ) n ++; } } cout << n << endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> #include <vector> #include <string> #include <cstring> using namespace std; int main() { string s; cin >> s; int n = 0; for(int i = 0; i < s.length(); i++){ int a = 0; int b = 0; int c = 0; for(int j = i; j < s.length(); j++){ if(s[j] == 'a') a++; if(s[j] == 'b') b++; if(s[j] == 'c') c++; if( (a==b || a==0 || b == 0) && (a==c || c == 0 || a == 0) && (c == b || b == 0 || c == 0) ) n ++; } } cout << n << endl; return 0; } |