The meaning of the question is somewhat elusive ~~ After reading this question for a long time, I learned this question. I used a variety of STL water ~~ Stack, map + stack... I thought the efficiency would be very low ~~ However, the time is 80 ms ~~ The result is relatively fast ~~
Program:
[Cpp]
# Include <iostream>
# Include <algorithm>
# Include <stdio. h>
# Include <string. h>
# Include <map>
# Include <cmath>
# Include <queue>
# Include <stack>
# Define OOS 2000000000
# Define ll 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;
}