#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); long long ile = 0; string s; cin >> s; for(int i = 0; i < s.length(); i++){ long long a = 0; long long b = 0; long long c = 0; for(int j = i; j < s.length(); j++){ if(s[j] == 'a') a++; else if(s[j] == 'b') b++; else c++; if((a == b && b == c) || (a == 0 && b == c) || (b == 0 && a == c) || (c == 0 && a == b) || (a == 0 && b == 0) || (a == 0 && c == 0) || (b == 0 && c == 0)) ile++; } } cout << ile << "\n"; }
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 | #include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); long long ile = 0; string s; cin >> s; for(int i = 0; i < s.length(); i++){ long long a = 0; long long b = 0; long long c = 0; for(int j = i; j < s.length(); j++){ if(s[j] == 'a') a++; else if(s[j] == 'b') b++; else c++; if((a == b && b == c) || (a == 0 && b == c) || (b == 0 && a == c) || (c == 0 && a == b) || (a == 0 && b == 0) || (a == 0 && c == 0) || (b == 0 && c == 0)) ile++; } } cout << ile << "\n"; } |