|
|
вернуться в форумWA26 Послано liuzy 27 сен 2012 13:54 I think my program is correct. Who can tell me why I got wa? #include<cstdio> #include<cstdlib> #include<cstring> char a[100005],b[100000]; char cs[]="=+-*/0123456789)("; bool pd(char ch){ for(int i=0;i<17;i++) if(ch==cs[i]) return 1; return 0; } int main(){ while(gets(b)){ strcat(a,b); } int len=strlen(a); int ha=0,k=0; for(int i=0;i<len;i++){ if(ha){ if(a[i]=='*' && a[i+1]==')') ha=0; }else{ if(a[i]=='*' && a[i-1]=='(') ha=1; else{ if(k>0 && (!pd(a[i]))){ printf("NO"); return 0; } if(a[i]=='(') k++; if(a[i]==')') k--; if(k<0) { printf("NO"); return 0;} } } } if(ha || k!=0) { printf("NO"); return 0; } else printf("YES"); system("pause"); return 0; } |
|
|