#include <iostream>
#include <string>
using namespace std;
int zbalansowane(string x)
{
int s=0;
int zbior[5];
for(int i=0;i<=x.length();i++)
{
for(int j=i;j<=x.length();j++)
{
int A=0,B=0,C=0;
int n=i;
do
{
if (x[n]=='a') A+=1;
if (x[n]=='b') B+=1;
if (x[n]=='c') C+=1;
n+=1;
} while (n!=j);
if (A==B==C || (A==B && C==0) || (A==C && B==0) || (B==C && A==0))
{
if (A==B==C==0) continue;
else s+=1;
}
}
}
return s;
}
int main()
{
string slowo;
cin>>slowo;
cout<<zbalansowane(slowo);
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 | #include <iostream> #include <string> using namespace std; int zbalansowane(string x) { int s=0; int zbior[5]; for(int i=0;i<=x.length();i++) { for(int j=i;j<=x.length();j++) { int A=0,B=0,C=0; int n=i; do { if (x[n]=='a') A+=1; if (x[n]=='b') B+=1; if (x[n]=='c') C+=1; n+=1; } while (n!=j); if (A==B==C || (A==B && C==0) || (A==C && B==0) || (B==C && A==0)) { if (A==B==C==0) continue; else s+=1; } } } return s; } int main() { string slowo; cin>>slowo; cout<<zbalansowane(slowo); return 0; } |
English