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? @\/@
思路:首先将符号根据两个[]和空格分割到数组中去然后根据后面给的数依次判断五个位置是否不符合范围要求也就是不存在那个符号,然后根据位置输出符号就行,在实际写的时候不知道为什么会存入一堆空元素,输出结果一直不对,单步调试的时候才发现是空元素的影响,然后就写了个方法来删除空元素.
判断的地方写的可能有点臃肿,不知道怎么快速判断所以就一个个判断了
代码`:
package test1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
public class PTA1052 {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] hand=br.readLine().split("[\\[\\] ]");
String[] eye=br.readLine().split("[\\[\\] ]");
String[] mouth=br.readLine().split("[\\[\\] ]");
hand=removeEmpty(hand);
eye=removeEmpty(eye);
mouth=removeEmpty(mouth);
int N=Integer.parseInt(br.readLine());
for(int i=0;i<N;i++){
String [] k=br.readLine().split("\\s+");
if(Integer.parseInt(k[0])<=0||Integer.parseInt(k[0])>hand.length||Integer.parseInt(k[1])<=0||Integer.parseInt(k[1])>eye.length||Integer.parseInt(k[2])<=0||Integer.parseInt(k[2])>mouth.length||
Integer.parseInt(k[3])<=0||Integer.parseInt(k[3])>eye.length||Integer.parseInt(k[4])<=0||Integer.parseInt(k[4])>hand.length){
System.out.println("Are you kidding me? @\\/@");
}
else {
System.out.println(hand[Integer.parseInt(k[0])-1]+"("+eye[Integer.parseInt(k[1])-1]+mouth[Integer.parseInt(k[2])-1]+eye[Integer.parseInt(k[3])-1]+")"+hand[Integer.parseInt(k[4])-1]);
}
}
}
private static String[] removeEmpty(String[] string) {
//定义一个list列表,并循环赋值
ArrayList<String> strList = new ArrayList<String>(Arrays.asList(string));
//删除list列表中所有的空值
while (strList.remove(null));
while (strList.remove(""));
//把list列表转换给一个新定义的中间数组,并赋值给它
return strList.toArray(new String[0]);
}
}