1052 卖个萌 (20 分)C++ PAT (Basic Level) Practice

1052 卖个萌 (20 分)
萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。
简单起见,我们假设一个表情符号是按下列格式输出的:

[左手] ([左眼][口][右眼])[右手]
现给出可选用的符号集合,请你按用户的要求输出表情。

输入格式:
输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号 []内。
题目保证每个集合都至少有一个符号,并不超过 10 个符号;
每个符号包含 1 到 4 个非空字符。

之后一行给出一个正整数 K,为用户请求的个数。
随后 K 行,每行给出一个用户的符号选择,顺序为左手、左眼、口、右眼、右手
——这里只给出符号在相应集合中的序号(从 1 开始),数字间以空格分隔。

输出格式:
对每个用户请求,在一行中输出生成的表情。
若用户选择的序号不存在,则输出 Are you kidding me? @/@。

输入样例:
[╮][╭][o][~\] [/~] [<][>]
[╯][╰][^][-][=][>][<][@][⊙]
[Д][▽][_][ε][^] …
4
1 1 2 2 2
6 8 1 5 5
3 3 4 3 3
2 10 3 9 3

输出样例:
╮(╯▽╰)╭
<(@Д=)/~
o(^ε^)o
Are you kidding me? @\/@

①不仅要判断输入的数字是否超过最大值,还要判断是否小于等于0
② substr的用法(start,length) 和find用法 (查找的字符c,start)
③输入带空格,不能用cin,需用getline
④输出每一个后面要带换行 “\n”
⑤转义字符:“Are you kidding me? @\/@”的\ 输出时要加转移\

//①不仅要判断输入的数字是否超过最大值,还要判断是否小于等于0 
//② substr的用法(start,length) 和find用法 (查找的字符c,start)
//③输入带空格,不能用cin,需用getline 
//④输出一个后面要带换行 “\n” 
#include<iostream>
using namespace std;
string hand,eye,mouth;

void drawface(string arr,int num){//画脸 
	int count=0;
	for(int i=0;i<arr.size();i++){
		if(arr[i]=='['){
			count++;
		}
		if(count==num){
			int j=i+1;
			cout<<arr.substr(j,arr.find(']',j)-j);
			//截取字符串substr(start,length) ,
			//int find(查找的字符c,start)
			return ;
		}
	}
}
void face(int num1,int num2,int num3,int num4,int num5){//画脸
	drawface(hand,num1);
	cout<<"(";
	drawface(eye,num2);
	drawface(mouth,num3);	
	drawface(eye,num4);
	cout<<")";
	drawface(hand,num5);
}

int countNum(string arr){//计算有多少个嘴
	int count=0;
	for(int i=0;i<arr.size();i++){
		if(arr[i]=='['){
			count++;
		}
	}
	return count;
}
int main(){
	
	getline(cin,hand);
	getline(cin,eye);
	getline(cin,mouth);
	
	int mouthcount=countNum(mouth);//计算有多少个嘴 
	int handcount=countNum(hand);
	int eyecount=countNum(eye);
	
	int K;
	int lefthand,lefteye,mouth,righteye,righthand;
	cin>>K;
	for(int i=0;i<K;i++){
		cin>>lefthand>>lefteye>>mouth>>righteye>>righthand;	//边输入边输出 

		if( (lefthand<=handcount&&lefteye<=eyecount&&mouth<=mouthcount&&righteye<=eyecount&&righthand<=handcount)
			&&(lefthand>0&&lefteye>0&&mouth>0&&righteye>0&&righthand>0)
		){
			face(lefthand,lefteye,mouth,righteye,righthand);
		}else{
			cout<<"Are you kidding me? @\\/@";
		}
		
//	if(i!=K-1){
		cout<<endl;	
//	}
	}	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值