#include <iostream>
#include <string>
using namespace std;
int add(int * N){
if(N[0]==0 && N[1]==0) return 1;
if(N[1]==0 && N[2]==0) return 1;
if(N[0]==0 && N[2]==0) return 1;
if(N[0]==0 && N[1]==N[2]) return 1;
if(N[1]==0 && N[0]==N[2]) return 1;
if(N[2]==0 && N[0]==N[1]) return 1;
if(N[0]==N[1] && N[1]==N[2]) return 1;
return 0;
}
void cl(int *N){
N[0]=0;N[1]=0;N[2]=0;
}
int main(){
string S;
int n,l=0,A[3];
cl(A);
cin >> S;
n=S.size();
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
if(S[j]=='a')A[0]++;
if(S[j]=='b')A[1]++;
if(S[j]=='c')A[2]++;
l+=add(A);
}
cl(A);
}
cout << l << 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 | #include <iostream> #include <string> using namespace std; int add(int * N){ if(N[0]==0 && N[1]==0) return 1; if(N[1]==0 && N[2]==0) return 1; if(N[0]==0 && N[2]==0) return 1; if(N[0]==0 && N[1]==N[2]) return 1; if(N[1]==0 && N[0]==N[2]) return 1; if(N[2]==0 && N[0]==N[1]) return 1; if(N[0]==N[1] && N[1]==N[2]) return 1; return 0; } void cl(int *N){ N[0]=0;N[1]=0;N[2]=0; } int main(){ string S; int n,l=0,A[3]; cl(A); cin >> S; n=S.size(); for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ if(S[j]=='a')A[0]++; if(S[j]=='b')A[1]++; if(S[j]=='c')A[2]++; l+=add(A); } cl(A); } cout << l << endl; return 0; } |
English