程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> CodeForces Round #123 (195C) - Try and Catch

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

編輯:C++入門知識

   題意有些難捉摸~~看了蠻久才懂...這題我是用各種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; 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved