PAT (Basic Level) Practice (中文)坑点分析(测试点)

#include<string>
#include<iostream>
#include<vector>
using namespace std;
int main() {
	string s1;
	vector<vector<string> >V(3);
	for (int i = 0; i < 3; i++) {
		getline(cin, s1);
		while (s1.find('[') != string::npos) {
			V[i].push_back(s1.substr(s1.find_first_of('[') + 1, s1.find_first_of(']') - s1.find_first_of('[') - 1));
			if (V[i][V[i].size() - 1] == "") { V[i].pop_back(); V[i].push_back(" "); }
			s1.erase(s1.begin() + s1.find_first_of('['), s1.begin() + s1.find_first_of(']') + 1);
		}
	}
	int n, tmp1, tmp2, tmp3, tmp4, tmp5;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d %d %d", &tmp1, &tmp2, &tmp3, &tmp4, &tmp5);
		if (tmp1 > V[0].size() || tmp2 > V[1].size() || tmp3 > V[2].size() ||
			tmp4 > V[1].size() || tmp5 > V[0].size()||tmp1<1||tmp2<1||tmp3<1||tmp4<1||tmp5<1) {
			printf("Are you kidding me? @\\/@\n"); continue;
		}
		printf("%s(%s%s%s)%s\n", V[0][tmp1 - 1].c_str(), V[1][tmp2 - 1].c_str(), V[2][tmp3 - 1].c_str(), V[1][tmp4 - 1].c_str(), V[0][tmp5 - 1].c_str());
	}
	return 0;
}

先上代码再分析。

这个题难点在于:
①:对数据读入的处理,如何把【】去除,并获取正确内容,这是很关键。
②:测试点对越界测试,测试点2是对输入的序号大于了可以选的眼,口,鼻的个数,测试点1的对下界,就是测试点输入了0号口,但是最小只存在1号口,不对其进行处理,就会导致段错误。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值