http://codeforces.com/problemset/problem/195/C
哇做这题真是一口老血喷出来,看了半天不知道啥意思,最后猜了猜题意,然后代码中各种bug,我也不确定理解的题意是不是对的,xjb调试,最后竟然过了。。。一道简单傻逼题但是出的看不懂。。。
题目大意:你有try和catch操作,每个catch操作保证前面有一次try和他相匹配。现在有一种异常的情况,是由throw引起的,throw中表示一个异常的类型,比如样例1的AE。然后继续执行程序,找到一个无法匹配到正常的block的AE,输出他的信息即可。样例1中AE in line5刚好和他上面的try匹配掉了,那个try是在throw后的,所以没事。到了AE somewhere,就只能匹配throw上面的try了,所以就有错,输出。
哇傻逼题,随便搞搞。
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main() {
char str[100] = {0}, ans_str[100] = {0}, tmp[100] = {0}, ch;
int cnt = 0, k, T;
bool flag = 0, key;
cin >> T;
ch = getchar();
while(ch != '\n')
ch = getchar();
while(T--) {
key = 0;
k = 0;
ch = getchar();
while(ch != '\n') {
if(ch == '"')
key = 1;
if(key)
str[k++] = ch;
else if(ch != ' ')
str[k++] = ch;
ch = getchar();
}
str[k++] = '\0';
if(flag) {
if(str[1] == 'r') // try
cnt++;
if(str[0] == 'c') {//catch
if(cnt)
cnt--;
else {
k = 0;
for(int i = 6; str[i] != ','; i++)
tmp[k++] = str[i];
tmp[k++] = '\0';
if(!strcmp(tmp, ans_str)) {
for(int i = 6 + k + 1; str[i] != '"'; i++)
cout << str[i];
cout << endl;
flag = 0;
}
}
}
}
if(str[1] == 'h') { // throw
flag = 1;
k = 0;
for(int i = 6; str[i] != ')'; i++)
ans_str[k++] = str[i];
ans_str[k++] = '\0';
}
}
if(flag)
cout << "Unhandled Exception" << endl;
return 0;
}