#include <cstdio> #include <cstring> int a,b,c,buf; char word[300005]; int main(){ scanf("%s",&word); int dlg = strlen(word); int all = 0; for(int i=0 ;i<dlg; i++){ a=b=c=0; for(int j=i; j<dlg; j++){ //buf=all; if(word[j]=='a') a++; if(word[j]=='b') b++; if(word[j]=='c') c++; if(a==0 && b==0 || b==0 && c==0 || a==0 && c==0){ all++; } else { if(a==0) { if(b == c) all++; } else if(b==0) { if(a == c) all++; } else if(c==0) { if(a == b) all++; } else { if( a == b && a == c) all++; } } /* if(buf!=all){ for(int a=i; a<=j; a++) printf("%c",word[a]); printf("\n"); } */ } } printf("%d",all); 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 | #include <cstdio> #include <cstring> int a,b,c,buf; char word[300005]; int main(){ scanf("%s",&word); int dlg = strlen(word); int all = 0; for(int i=0 ;i<dlg; i++){ a=b=c=0; for(int j=i; j<dlg; j++){ //buf=all; if(word[j]=='a') a++; if(word[j]=='b') b++; if(word[j]=='c') c++; if(a==0 && b==0 || b==0 && c==0 || a==0 && c==0){ all++; } else { if(a==0) { if(b == c) all++; } else if(b==0) { if(a == c) all++; } else if(c==0) { if(a == b) all++; } else { if( a == b && a == c) all++; } } /* if(buf!=all){ for(int a=i; a<=j; a++) printf("%c",word[a]); printf("\n"); } */ } } printf("%d",all); return 0; } |