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到死了、、、、、、这是我的程序,看看有什么bug不?? #include<iostream> using namespace std; int main() { char word_1[300],word[300]; int num,i,j,k,l; int len; int flag[300]; scanf("%d",&num); getchar(); while(num--) { gets(word_1); len=strlen(word_1); j=0; for(i=0;i<len;i++) { if(word_1[i]==' ') continue; word[j]=word_1[i]; j++; } word[j]='\0'; len=strlen(word); memset(flag,0,sizeof(flag)); for(i=len-1;i>=0;i--) { if(word[i]=='('&&word[i+2]==')') { flag[i+2]=1; word[i]='~'; word[i+2]='~'; continue; } if(word[i]=='('&&( word[i-1]=='+' || i==0 || word[i-1]=='(' )) { j=i+1; while(1) { if(word[j]==')'&&flag[j]==0) break; j++; } flag[j]=1; word[i]='~'; word[j]='~'; } if(word[i]=='('&&word[i-1]=='-') { int temp=0; j=i+1; while(1) { if(word[j]==')') break; j++; if(word[j]=='+'||word[j]=='-') temp++; } if(temp==0) { word[i]='~'; word[j]='~'; flag[j]=1; } } } for(i=0;i<len;i++) { if(word[i]=='~') continue; printf("%c",word[i]); } printf("\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