#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
string S;
cin >> S;
int l = S.size();
int tab[l + 1][26];
for(int i = 0; i < 26; i++)
{
tab[0][i] = 0;
}
for(int i = 1; i <= l; i++)
{
for(int x = 0; x < 26; x++)
{
tab[i][x] = tab[i - 1][x];
}
tab[i][(int)S[i - 1] - (int)'a']++;
}
int pom[26];
int k;
int pop;
long long wyn = 0;
for(int i = 0; i <= l; i++)
{
for(int x = i + 1; x <= l; x++)
{
for(int y = 0; y < 26; y++)
{
pom[y] = tab[x][y] - tab[i][y];
}
k = 1;
pop = -1;
for(int y = 0; y < 26; y++)
{
if(pom[y])
{
if(pop != -1)
{
if(pom[y] != pop)
{
k = 0;
break;
}
}
pop = pom[y];
}
}
wyn += k;
}
}
cout << wyn << endl;
return 0;
}
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); string S; cin >> S; int l = S.size(); int tab[l + 1][26]; for(int i = 0; i < 26; i++) { tab[0][i] = 0; } for(int i = 1; i <= l; i++) { for(int x = 0; x < 26; x++) { tab[i][x] = tab[i - 1][x]; } tab[i][(int)S[i - 1] - (int)'a']++; } int pom[26]; int k; int pop; long long wyn = 0; for(int i = 0; i <= l; i++) { for(int x = i + 1; x <= l; x++) { for(int y = 0; y < 26; y++) { pom[y] = tab[x][y] - tab[i][y]; } k = 1; pop = -1; for(int y = 0; y < 26; y++) { if(pom[y]) { if(pop != -1) { if(pom[y] != pop) { k = 0; break; } } pop = pom[y]; } } wyn += k; } } cout << wyn << endl; return 0; } |
English