Advertisement
Guest User

Untitled

a guest
Jun 10th, 2012
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <string>
  7. #include <cmath>
  8. #include <cassert>
  9. #include <ctime>
  10. #include <algorithm>
  11. #include <queue>
  12. #include <memory.h>
  13. #include <stack>
  14. #define mp make_pair
  15. #define pb push_back                    
  16. #define setval(a,v) memset(a,v,sizeof(a))
  17.  
  18. #if ( _WIN32 || __WIN32__ )
  19.     #define LLD "%I64d"
  20. #else
  21.     #define LLD "%lld"
  22. #endif
  23.  
  24. using namespace std;
  25.  
  26. typedef long long ll;
  27. typedef long double ld;
  28.  
  29.  
  30. string s;
  31. char buf[2100];
  32. char buf2[2100];
  33.  
  34. int main(){
  35.   #ifdef LOCAL
  36.     freopen("input.txt","r",stdin);
  37.     freopen("output.txt","w",stdout);
  38.   #endif
  39.     getline(cin,s);
  40.     int t;
  41.     sscanf(s.data(),"%d",&t);
  42.  
  43.     string exc;
  44.  
  45.     int topass = 0;
  46.  
  47.     for (int it = 0; it < t; it++){
  48.         getline(cin,s);      
  49.         s+= char(1);
  50.         char c;
  51.         if (sscanf(s.data()," throw ( %[^ )] ) %c",buf,&c) == 2){
  52.             exc = buf;
  53.             assert(c == 1);
  54.         }
  55.         else if (sscanf(s.data(), " try %c ",&c) == 1){
  56.             assert(c == 1);
  57.             if (exc != "")
  58.                 topass++;
  59.         } else if ((sscanf(s.data(), " catch ( %[^ ,] , \"%[^\"]\" ) %c",buf,buf2,&c))==3){
  60.             assert(c == 1);
  61.             if (exc != ""){
  62.                 if (topass == 0 && buf == exc){
  63.                    printf("%s\n",buf2);
  64.                    return 0;
  65.                 }
  66.                 --topass;
  67.                 topass = max(topass,0);
  68.             }
  69.         } else {
  70.           assert(sscanf(s.data()," %c",&c) == 1);
  71.           assert(c == 1);
  72.         }        
  73.     }
  74.  
  75.     printf("Unhandled Exception\n");                                                      
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement