PAT Basic 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? @\/@

  题解:我发现这几道题是真的坑,这道题主要有两个坑点:
  ①"Are you kidding me? @\/@"需要写成"Are you kidding me? @\\/@",因为\是转义符号。
  ②输出"Are you kidding me? @\\/@"时,用户给出的不一定是大于这个数据的数据量,也有可能是0或负数
  这道题还需要注意处理输入的问题,用判断[的方式来输入我个人觉得是一个比较好的方法。
代码如下:
 1 #include<iostream>
 2 #include<string>
 3 
 4 using namespace std;
 5 
 6 int get( string temp, string a[])
 7 {
 8     int k = 0;
 9     for( int i = 0; i < temp.length(); i++){
10         if( temp[i] == '['){
11             i++;
12             while(temp[i] != ']'){
13                 a[k] += temp[i];
14                 i++;
15             }
16             k++;
17         }
18     }
19     return k;
20 }
21 
22 int main()
23 {
24     int k, temp[5];
25     string mouth, eye, hand;
26     string a[15], b[15], c[15];
27     getline( cin, hand);
28     getline( cin, eye);
29     getline( cin, mouth);
30     int len1 = get( hand, a);
31     int len2 = get( eye, b);
32     int len3 = get( mouth, c);
33     
34     scanf("%d",&k);
35     while(k--){
36         bool temp3 = true;
37         for( int i = 0; i < 5; i++){
38             scanf("%d",&temp[i]);
39         }
40         if( temp[0] > len1 || temp[0] < 1)
41             temp3 = false;
42         else if( temp[1]  > len2 || temp[1] < 1)
43             temp3 = false;
44         else if( temp[2]  > len3 || temp[2] < 1)
45             temp3 = false;
46         else if( temp[3]  > len2 || temp[3] < 1)
47             temp3 = false;
48         else if( temp[4]  > len1 || temp[4] < 1)
49             temp3 = false;
50         if( !temp3){
51             cout << "Are you kidding me? @\\/@" << endl;
52             continue;
53         }
54         else{
55             cout<<a[temp[0]-1]<<"("<<b[temp[1]-1]<<c[temp[2]-1]<<b[temp[3]-1]<<")"<<a[temp[4]-1]<<endl;
56         }
57     }
58     return 0;
59 }
 

猜你喜欢

转载自www.cnblogs.com/yxp400/p/9461719.html
今日推荐