#include <iostream> #include <string> using namespace std; string s; int main() { ios_base::sync_with_stdio(0); cin >> s; int output = 0; for(int i=0; i<s.length(); i++) { int a=0,b=0,c=0; for(int j=i; j<s.length(); j++) { switch(s[j]) { case 'a': a++; break; case 'b': b++; break; case 'c': c++; break; } if(a == 0) { if(b == 0) { if(c == 0) cerr << "impossible" << endl; else output++; } else { if(c == 0) output++; else if(b == c) output++; } } else { if(b == 0) { if(c == 0) output++; else if(a == c) output++; } else { if(c == 0) { if(a == b) output++; } else if(a == b && b == c) output++; } } } } cout << output << endl; }
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <iostream> #include <string> using namespace std; string s; int main() { ios_base::sync_with_stdio(0); cin >> s; int output = 0; for(int i=0; i<s.length(); i++) { int a=0,b=0,c=0; for(int j=i; j<s.length(); j++) { switch(s[j]) { case 'a': a++; break; case 'b': b++; break; case 'c': c++; break; } if(a == 0) { if(b == 0) { if(c == 0) cerr << "impossible" << endl; else output++; } else { if(c == 0) output++; else if(b == c) output++; } } else { if(b == 0) { if(c == 0) output++; else if(a == c) output++; } else { if(c == 0) { if(a == b) output++; } else if(a == b && b == c) output++; } } } } cout << output << endl; } |