ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1027. D++ Again

WA26
Posted by liuzy 27 Sep 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;
}