1. 程式人生 > >1052 賣個萌

1052 賣個萌

萌萌噠表情符號通常由“手”、“眼”、“口”三個主要部分組成。簡單起見,我們假設一個表情符號是按下列格式輸出的:

[左手]([左眼][口][右眼])[右手]

現給出可選用的符號集合,請你按使用者的要求輸出表情。

輸入格式:

輸入首先在前三行順序對應給出手、眼、口的可選符號集。每個符號括在一對方括號 []內。題目保證每個集合都至少有一個符號,並不超過 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? @\/@

分析:

       這是一個字串處理的問題,因為一開始給定的表情符號中可能會有空格,所以這裡選用getline()。對'[' ']' ' '三個字元做一下特殊處理,將其他內容存入字串陣列即可。

       如果說我踩了的什麼坑的話,就是輸入資料可能會小於1。一開始沒對此加判斷,樣例2,3沒過,加上就好了。

#include<iostream>

using namespace std;

int main(){
	string hand[10000], eyes[10000], mouth[10000];
	string s;
	int K;
	int cnt1 = 1, cnt2 = 1, cnt3 = 1;
	for(int i = 0; i < 3; i++){
		getline(cin, s);
		//依次為頭、眼、手 
		if(i == 0){
			for(int i = 0; i < s.length(); i++){
				if(s[i] == '[' || s[i] == ' ') continue;
				else if(s[i] == ']') cnt1++;
				else hand[cnt1] += s[i];
			}
		}else if(i == 1){
			for(int i = 0; i < s.length(); i++){
				if(s[i] == '[' || s[i] == ' ') continue;
				else if(s[i] == ']') cnt2++;
				else eyes[cnt2] += s[i];
			}
		}else{
			for(int i = 0; i < s.length(); i++){
				if(s[i] == '[' || s[i] == ' ') continue;
				else if(s[i] == ']') cnt3++;
				else mouth[cnt3] += s[i];
			}
		}
	}
	cin >> K;
	for(int i = 0; i < K; i++){
		int temp1, temp2, temp3, temp4, temp5;
		cin >> temp1 >> temp2 >> temp3 >> temp4 >> temp5;
		if(temp1 >= cnt1 || temp5 >= cnt1 || temp2 >= cnt2 || temp4 >= cnt2 || temp3 >= cnt3 ||
			temp1 < 1 || temp2 < 1 || temp3 < 1 || temp4 < 1 || temp5 < 1){
			cout << "Are you kidding me? @\\/@" << endl;
		}else{
			cout << hand[temp1] << '(' << eyes[temp2] << mouth[temp3] << eyes[temp4] << ')' << hand[temp5] << endl;
		}
	}
}