CodeForces Round #123 (195C) - Try and Catch

     题意有些难捉摸~~看了蛮久才懂...这题我是用各种STL水过的了~~stack,map+stack...本以为效率会很低~~但时间为80MS..去status瞅瞅~~结果还算比较快的~~


Program:

#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;
}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值