天天看點

1052 賣個萌(JAVA)

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

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

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

輸入格式:

輸出格式:

輸入樣例:

[╮][╭][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 m      

代碼實作:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);  
        String h = sc.nextLine().trim();
        String[] hands = h.substring(h.indexOf("[") + 1, h.lastIndexOf(']')).split("\\]\\s*\\[");
        String e = sc.nextLine().trim();
        String[] eyes = e.substring(h.indexOf("[") + 1, e.lastIndexOf(']')).split("\\]\\s*\\[");
        String m = sc.nextLine().trim();
        String[] mouths = m.substring(h.indexOf("[") + 1, m.lastIndexOf(']')).split("\\]\\s*\\[");

        int n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            String[] in = sc.nextLine().split("\\s+");
            String temp = "";
            boolean flag = true;
            if (Integer.parseInt(in[0]) <= hands.length) {
                temp = temp + hands[Integer.parseInt(in[0]) - 1] + "(";
            } else {
                System.out.println("Are you kidding me? @\\/@");
                flag = false;
                continue;
            }

            if (Integer.parseInt(in[1]) <= eyes.length) {
                temp = temp + eyes[Integer.parseInt(in[1]) - 1];
            } else {
                System.out.println("Are you kidding me? @\\/@");
                flag = false;
                continue;
            }

            if (Integer.parseInt(in[2]) <= mouths.length) {
                temp = temp + mouths[Integer.parseInt(in[2]) - 1];
            } else {
                System.out.println("Are you kidding me? @\\/@");
                flag = false;
                continue;
            }

            if (Integer.parseInt(in[3]) <= eyes.length) {
                temp = temp + eyes[Integer.parseInt(in[3]) - 1];
            } else {
                System.out.println("Are you kidding me? @\\/@");
                flag = false;
                continue;
            }

            if (Integer.parseInt(in[4]) <= hands.length) {
                temp = temp + ")" + hands[Integer.parseInt(in[4]) - 1];
            } else {
                System.out.println("Are you kidding me? @\\/@");
                flag = false;
                continue;
            }
            if (flag) {
                System.out.println(temp);
            }

        }

    }
}