CodeFroces 195C. Try and Catch(阅读理解+猜题意+构造)

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值