PAT B1052 卖个萌思路方法以及测试点 1 2 解决

B组刷题汇总~

1.测试点解决

0号测试点为题目给出的测试用例,1号测试点数组中含有 0 值,需进行特判,2号测试点中含有负数值,需要进行特判

2.注意点

题目所给输出无法正常全部输出,需要额外添加转义符号。

3.代码(C++)

使用了stl 容器中的 string。

#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;

const int maxn = 11;



int main(){
    string hands[maxn],eyes[maxn],mouths[maxn];
	string hand,eye,mouth;
	int handnum = 0,eyenum = 0,mouthnum = 0;
	getline(cin,hand);
	for(int i = 0;i < hand.size();i++){
		if(hand[i] == '['){
			i++;
			while(hand[i] != ']'){
                if(hand[i] != ' '){
                    hands[handnum] += hand[i];
                }
				i++;
			}
			handnum++;
		}
	}
	getline(cin,eye);
	for(int i = 0;i < eye.size();i++){
		if(eye[i] == '['){
			i++;
			while(eye[i] != ']'){
                    if(eye[i] != ' '){
                        eyes[eyenum] += eye[i];
                    }

				i++;
			}
			eyenum++;
		}
	}
	getline(cin,mouth);
	for(int i = 0;i < mouth.size();i++){
		if(mouth[i] == '['){
			i++;
			while(mouth[i] != ']'){
                    if(mouth[i] != ' '){
                        mouths[mouthnum] += mouth[i];
                    }
				i++;
			}
			mouthnum++;
		}
	}

	int n;
	scanf("%d",&n);
	int sea[n][6];
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 5;j++){
			scanf("%d",&sea[i][j]);
		}
	}
	for(int i = 0;i < n;i++){
            //以下为判别语句。
		if(sea[i][0] > handnum || sea[i][1] > eyenum || sea[i][2] > mouthnum || sea[i][3] > eyenum || sea[i][4] > handnum || sea[i][0] <= 0 || sea[i][1] <= 0 || sea[i][2] <= 0 || sea[i][3] <= 0 || sea[i][4] <= 0){
			printf("Are you kidding me? @\\/@\n"); //额外添加转义符!!!
		}else{
			cout << hands[sea[i][0] - 1] << "("<< eyes[sea[i][1] - 1] << mouths[sea[i][2] - 1] << eyes[sea[i][3] - 1] <<")"<< hands[sea[i][4] - 1] << '\n';
		}
	}
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值