Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
自己测试都没错,不知为什么老WA,请高手帮帮我,代码如下#include <stdio.h> bool wrong(char c) { if(c=='='||c=='+'||c=='-'||c=='*'||c=='/'||(c<58&&c>47)||c=='('||c==')') return false; else return true; } int main() { char s[10000],c,ss[10000]; int l=0,zs_start,i,j,stack; while(1==scanf("%c",&c)) { if(c!='\n') { s[l]=c; l++; } } ss[0]=s[0]; zs_start=0; for(i=1,j=1;i<l;i++,j++) { ss[j]=s[i]; if(!zs_start&&s[i-1]=='('&&s[i]=='*') { zs_start=i; continue; } if(zs_start&&s[i]==')'&&s[i-1]=='*'&&i>zs_start+1) { j-=i-zs_start+2; zs_start=0; } } l=j; stack=0; for(i=0;i<l;i++) { // printf("%c",ss[i]); if(ss[i]=='(') stack++; else { if(ss[i]==')') stack--; if(stack<0) break; } if(stack) if( wrong(ss[i]) ) break; } if(stack) printf("NO\n"); else printf("YES\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator