#include <iostream>
#include <cstring>
using namespace std;
const int R=3000000;
char tekst1[ R ] = { 'a', 'a', 'b', 'b', 'a', 'b',
'c', 'c', 'c','b','a', '\0' };
int ilosc(char tekst[],char znak)
{
int dl=strlen(tekst);
int k=0;
for(int i=0;i<=dl;i++)
if (znak==tekst[i]) k++;
return k;
}
bool spr(char tekst[])
{
int dl=strlen(tekst);
int a=ilosc(tekst,'a');
int b=ilosc(tekst,'b');
int c=ilosc(tekst,'c');
if(dl==1) return true;else
if(a==0&&b==0) return true;else
if(c==0&&b==0) return true;else
if(a==0&&c==0) return true;else
if(a==c&& b==0) return true;else
if(b==c&& a==0) return true;else
if(a==b&& c==0) return true;else
if(a==b && b==c) return true;else
return false;
}
int wynik=0;
int main()
{
cin>>tekst1;
int dl=strlen(tekst1);
char tekst4[R];
for(int j=1;j<=dl+1;j++)
{
for(int k=0;k<dl;k++)
tekst4[k]=' ';
for(int i=j;i<dl+1;i++)
{
strncpy(tekst4,tekst1,i);
if (spr(tekst4)){
wynik++;}
}
tekst1[j-1]=' ';
}
cout<<wynik;
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 | #include <iostream> #include <cstring> using namespace std; const int R=3000000; char tekst1[ R ] = { 'a', 'a', 'b', 'b', 'a', 'b', 'c', 'c', 'c','b','a', '\0' }; int ilosc(char tekst[],char znak) { int dl=strlen(tekst); int k=0; for(int i=0;i<=dl;i++) if (znak==tekst[i]) k++; return k; } bool spr(char tekst[]) { int dl=strlen(tekst); int a=ilosc(tekst,'a'); int b=ilosc(tekst,'b'); int c=ilosc(tekst,'c'); if(dl==1) return true;else if(a==0&&b==0) return true;else if(c==0&&b==0) return true;else if(a==0&&c==0) return true;else if(a==c&& b==0) return true;else if(b==c&& a==0) return true;else if(a==b&& c==0) return true;else if(a==b && b==c) return true;else return false; } int wynik=0; int main() { cin>>tekst1; int dl=strlen(tekst1); char tekst4[R]; for(int j=1;j<=dl+1;j++) { for(int k=0;k<dl;k++) tekst4[k]=' '; for(int i=j;i<dl+1;i++) { strncpy(tekst4,tekst1,i); if (spr(tekst4)){ wynik++;} } tekst1[j-1]=' '; } cout<<wynik; return( 0 ); } |
English