#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string slow; cin>>slow; int ilc,ilb,ila; long long il=0; for(int i=0;i<slow.size();i++){ ilc=0;ilb=0;ila=0; for(int j=i;j<slow.size();j++){ if(slow[j]=='a'){ ila++; } else if(slow[j]=='b'){ ilb++; } else if(slow[j]=='c'){ ilc++; } if(ilc==ilb and ilb==ila){ il++; } else if(ilc==0 and ilb==0){ il++; } else if(ilb==0 and ila==0){ il++; } else if(ila==0 and ilc==0){ il++; } else if(ila==0 and ilb==ilc){ il++; } else if(ilb==0 and ila==ilc){ il++; } else if(ilc==0 and ila == ilb){ il++; } } } cout<<il<<"\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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string slow; cin>>slow; int ilc,ilb,ila; long long il=0; for(int i=0;i<slow.size();i++){ ilc=0;ilb=0;ila=0; for(int j=i;j<slow.size();j++){ if(slow[j]=='a'){ ila++; } else if(slow[j]=='b'){ ilb++; } else if(slow[j]=='c'){ ilc++; } if(ilc==ilb and ilb==ila){ il++; } else if(ilc==0 and ilb==0){ il++; } else if(ilb==0 and ila==0){ il++; } else if(ila==0 and ilc==0){ il++; } else if(ila==0 and ilb==ilc){ il++; } else if(ilb==0 and ila==ilc){ il++; } else if(ilc==0 and ila == ilb){ il++; } } } cout<<il<<"\n"; } |