// Project: zba #include <bits/stdc++.h> using namespace std; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s; int w = 0; for (int i = 0; i < s.size(); i++) { int a = 0, b = 0, c = 0, len = 0; for (int j = i; j < s.size(); j++) { len++; switch (s[j]) { case 'a': a++; break; case 'b': b++; break; case 'c': c++; break; } if (a == len || b == len || c == len || (a == b && c == 0) || (a == c && b == 0) || (b == c && a == 0) || (a == b && b == c)) { w++; } } } cout << w << 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 | // Project: zba #include <bits/stdc++.h> using namespace std; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s; int w = 0; for (int i = 0; i < s.size(); i++) { int a = 0, b = 0, c = 0, len = 0; for (int j = i; j < s.size(); j++) { len++; switch (s[j]) { case 'a': a++; break; case 'b': b++; break; case 'c': c++; break; } if (a == len || b == len || c == len || (a == b && c == 0) || (a == c && b == 0) || (b == c && a == 0) || (a == b && b == c)) { w++; } } } cout << w << endl; } |