题意有些难捉摸~~看了蛮久才懂...这题我是用各种STL水过的了~~stack,map+stack...本以为效率会很低~~但时间为80MS..去status瞅瞅~~结果还算比较快的~~
Program: [cpp] #include #include #include #include #include #include #include #include #define oo 2000000000 #define ll long long using namespace std; struct node { stack ms; }; stack StackOfTry; map MapOfType; string str; int n,m,p,k,len,i; char s[80]; bool f; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); scanf("%d\n",&m); f=true; MapOfType.clear(); for (p=1;p<=m;p++) { gets(s); len=strlen(s); for (i=0;i if (s[i]=='t' && s[i+1]=='r') { StackOfTry.push(p); }else if (s[i]=='t') { i+=5; for (;i if (s[i]!='(' && s[i]!=' ') break; str=""; for (;i str+=s[i]; MapOfType[str].ms.push(p); }else if (s[i]=='c') { k=StackOfTry.top(); StackOfTry.pop(); i+=5; for (;i if (s[i]!='(' && s[i]!=' ') break; str=""; for (;i str+=s[i]; if (MapOfType.find(str)!=MapOfType.end()) if (!MapOfType[str].ms.empty()) if (MapOfType[str].ms.top()>k) { f=false; MapOfType[str].ms.pop(); for (;i if (s[i]=='"') break; i++; for (;s[i]!='"';i++) printf("%c",s[i]); printf("\n"); } } } if (f) printf("Unhandled Exception\n"); return 0; }