//Wojciech Filipek #include "bits/stdc++.h" using namespace std; int policz(string sl, int znak){ char litera; int ile = 0; if(znak == 1) litera = 'a'; else if(znak == 2) litera = 'b'; else litera = 'c'; for(int i = 0; i < sl.length(); i++){ if(sl[i] == litera) ile++; } return ile; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); string slowo; cin >> slowo; int a, b, c = 0; string test; int wynik = 0; for(int i = 0; i < slowo.length(); i++){ for(int k = slowo.length(); k > i; k--){ test = slowo.substr(i,k-i); int a = policz(test, 1); int b = policz(test, 2); int c = policz(test, 3); if(a == b && b == c || b == 0 && c == 0 || a == 0 && b == 0 || a == 0 && c == 0 || a == b && c == 0 || a == c && b == 0 || b == c && a == 0) wynik++; } } cout << wynik << 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 40 41 42 43 44 45 46 47 | //Wojciech Filipek #include "bits/stdc++.h" using namespace std; int policz(string sl, int znak){ char litera; int ile = 0; if(znak == 1) litera = 'a'; else if(znak == 2) litera = 'b'; else litera = 'c'; for(int i = 0; i < sl.length(); i++){ if(sl[i] == litera) ile++; } return ile; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); string slowo; cin >> slowo; int a, b, c = 0; string test; int wynik = 0; for(int i = 0; i < slowo.length(); i++){ for(int k = slowo.length(); k > i; k--){ test = slowo.substr(i,k-i); int a = policz(test, 1); int b = policz(test, 2); int c = policz(test, 3); if(a == b && b == c || b == 0 && c == 0 || a == 0 && b == 0 || a == 0 && c == 0 || a == b && c == 0 || a == c && b == 0 || b == c && a == 0) wynik++; } } cout << wynik << endl; } |