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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.