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 |
为 什么会 出现 错误呢 ?someone helps!~#include <cstdlib> #include <iostream> using namespace std; char an[105]; int cn[105],n; inline bool check(char a,char b){ if(a=='('&&b==')')return true; if(a=='['&&b==']')return true; return false; } bool angle(int a){ if(a==n-1)return false; for(int i=(cn[a]!=-1)?(cn[a]+1):a+1;i<n;i++){ if(cn[i]!=-1&&(an[i]==')'||an[i]==']')){ if(angle(cn[i])==false) return false; cn[i]=-1; } if(check(an[a],an[i])==true){ cn[i]=a; cn[a]=i; return true; } } return false; } void print(int i){ if(an[i]=='('||an[i]==')'){ printf("()"); return ; } if(an[i]=='['||an[i]==']'){ printf("[]"); return ; } } int main(int argc, char *argv[]) { while(gets(an)){ memset(cn,-1,sizeof(cn)); n=strlen(an); for(int i=0;i<n;i++){ if(an[i]==')'||an[i]==']')continue; angle(i); } for(int i=0;i<n;i++){ if(cn[i]!=-1)printf("%c",an[i]); else print(i); } printf("\n"); } system("PAUSE"); return EXIT_SUCCESS; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator