CodeForces Round #123 (195C) - Try and Catch
题意有些难捉摸~~看了蛮久才懂...这题我是用各种STL水过的了~~stack,map+stack...本以为效率会很低~~但时间为80MS..去status瞅瞅~~结果还算比较快的~~
Program:
[cpp]
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#define oo 2000000000
#define ll long long
using namespace std;
struct node
{
stack<int> ms;
};
stack<int> StackOfTry;
map<string,node> 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<len;i++) if (s[i]!=' ') break;
if (s[i]=='t' && s[i+1]=='r')
{
StackOfTry.push(p);
}else
if (s[i]=='t')
{
i+=5;
for (;i<len;i++)
if (s[i]!='(' && s[i]!=' ') break;
str="";
for (;i<len && s[i]!=')' && s[i]!=' ';i++)
str+=s[i];
MapOfType[str].ms.push(p);
}else
if (s[i]=='c')
{
k=StackOfTry.top();
StackOfTry.pop();
i+=5;
for (;i<len;i++)
if (s[i]!='(' && s[i]!=' ') break;
str="";
for (;i<len && s[i]!=',' && s[i]!=' ';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<len;i++)
if (s[i]=='"') break;
i++;
for (;s[i]!='"';i++)
printf("%c",s[i]);
printf("/n");
}
}
}
if (f) printf("Unhandled Exception/n");
return 0;
}