#include <iostream>
#include <string>
#include <array>
using namespace std;
using stan_t = array< int, 3 >;
int main()
{
string slowo;
cin >> slowo;
int dlgsc = slowo.length();
long long wynik = 0;
for (int pocz = 0; pocz < dlgsc; ++pocz) {
stan_t stan = {0, 0, 0};
for (int koniec = pocz; koniec < dlgsc; ++koniec) {
char const litera = slowo[koniec];
stan[litera - 'a'] += 1;
int const bonus = (
((stan[0] == 0) || (stan[1] == 0) || (stan[0] == stan[1])) &&
((stan[0] == 0) || (stan[2] == 0) || (stan[0] == stan[2])) &&
((stan[1] == 0) || (stan[2] == 0) || (stan[1] == stan[2]))
) ? 1 : 0;
wynik += bonus;
}
}
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 | #include <iostream> #include <string> #include <array> using namespace std; using stan_t = array< int, 3 >; int main() { string slowo; cin >> slowo; int dlgsc = slowo.length(); long long wynik = 0; for (int pocz = 0; pocz < dlgsc; ++pocz) { stan_t stan = {0, 0, 0}; for (int koniec = pocz; koniec < dlgsc; ++koniec) { char const litera = slowo[koniec]; stan[litera - 'a'] += 1; int const bonus = ( ((stan[0] == 0) || (stan[1] == 0) || (stan[0] == stan[1])) && ((stan[0] == 0) || (stan[2] == 0) || (stan[0] == stan[2])) && ((stan[1] == 0) || (stan[2] == 0) || (stan[1] == stan[2])) ) ? 1 : 0; wynik += bonus; } } cout << wynik << endl; } |
English