PAT乙级1052 卖个萌 (20 分)测试点123

本文详细解析了PAT乙级编程题目1052——卖个萌,重点讨论了测试点1、2出现的下界溢出问题,以及测试点0中转义字符的正确使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://pintia.cn/problem-sets/994805260223102976/problems/994805273883951104

测试点0:Are you kidding me? @/@中“\”为转义字符 要用双\表示
测试点1:最后一个表情是下界溢出
测试点2:中间有表情下界溢出

#include <iostream>
using namespace std;

int f(string a[], string s){
	int cnt = 0;
	for(int i = 0; i < s.size(); i++){
		while(s[i] == '['){
			string tmp = "";
			cnt++, ++i;
			while(s[i] != ']')
				tmp += s[i++];
			a[cnt] = tmp;
			break;
		}
	}
	return cnt;
}

int main(){
	string hand, eye, mouth, h[15], e[11], m[11];
	int n, cnth = 0, cnte = 0, cntm = 0;
	getline(cin, hand); getline(cin, eye); getline(cin, mouth);
	cnth = f(h, hand); cnte = f(e, eye); cntm = f(m, mouth);
	cin >> n;
	for(int i = 0; i < n; i++){
		int n1, n2, n3, n4, n5;
		cin >> n1 >> n2 >> n3 >> n4 >> n5;
		if(n1 <= 0 || n2 <= 0 || n3 <= 0 || n4 <= 0 || n5 <= 0){
			cout << "Are you kidding me? @\\/@" << endl;
			continue;
		}
		if(n1 <= cnth && n5 <= cnth && n2 <= cnte && n4 <= cnte && n3 <= cntm)
			cout << h[n1] << "(" << e[n2] << m[n3] << e[n4] << ")" << h[n5] << endl;
		else
			cout << "Are you kidding me? @\\/@" << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值