|
|
вернуться в форумWhat's Wrong With My Programm? I try the test all given of your suggestion, such as (*),(+),(((()()()()()((((((()))))(*)..... my programme's answer is right! but I still got WA! Why? who can help me to find my false! the programm is below: PS:If the symbol is '\n',I ignore it.Can I? #include <stdio.h> #include <iostream.h> int gettype(char ch) { if(ch=='+'||ch=='-'||ch=='/'||ch=='='||(ch>='0'&&ch<='9')) return 1; else if(ch=='*') return 8; else if(ch=='(') return 9; else if(ch==')') return 0; else return 2; } void main() { char *buf=new char[10000]; int i=0,L,t,flag=0,tmp1,k=0; char ch,chtmp; ch=getchar(); if(ch!='\n') buf[i++]=ch; while(ch!=EOF) { ch=getchar(); if(ch!='\n') buf[i++]=ch; } buf[i-1]='\0'; L=i-1;i=0; while(i<L-1) { ch=buf[i]; if(ch=='(') { tmp1=i+1;chtmp=buf[tmp1]; while(chtmp=='(') {tmp1++;chtmp=buf[tmp1];} if(gettype(chtmp)==1&&chtmp!='*') { chtmp=buf[i];t=gettype(chtmp); while(t!=2) { if(t==9&&buf[i+1]=='*') { i+=2; while(buf[i]! ='*'&&buf[i+1]!=')'&&i<L) i++; if(buf[i]!='*'&&buf [i+1]!=')') {flag=1;cout<<"NO";return;} i+=2; } else if(t==9&&buf[i+1]!='*') {k++;i++;} else if(t==0) {k--;i++;} else if(t==2) {flag=1;cout<<"NO";return;} else i++; chtmp=buf[i];t=gettype(chtmp);
} if(k!=0) {cout<<"NO";return;} } else if(chtmp=='*') { i+=2; while(buf[i]!='*'&&buf[i+1]!=')'&&i<L) i++; if(buf[i]!='*'||buf[i+1]!=')') {cout<<"NO";return;} i+=2; } else i++; } else i++; } cout<<"YES\n"; } Re: What's Wrong With My Programm? You return YES on this test ))(( Good luck. |
|
|