[Kick Start 2022 #Session 1] Centauri Prime

Titu·2022년 2월 15일
0

Algorithm

목록 보기
28/28

Problem

Alice and Bob are playing the game called Centauri Prime. Centauri Prime represents a planet which is split into several independent kingdoms. Before they start playing the game, they have to choose rulers for each kingdom. Alice and Bob mutually decided to distribute kingdoms based on the letter the kingdom's name ended with. Alice loves vowels and decided to rule kingdoms whose names ended in a vowel. Bob loves consonants and decided to rule kingdoms whose names ended in a consonant. Both of them do not like the letter 'y'(case insensitive) and thus, all kingdoms whose names ended in the letter 'y' are left without a ruler. Can you write a program that will determine the rulers of several kingdoms, given the kingdoms' names?

Input

The first line of the input gives the number of test cases, T. T lines follow, each one containing the name of one kingdom. Kingdom names will consist of only lower case English letters, starting with a capital letter. There will be no other characters on any line, and no empty lines.
List of vowels for this problem is ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'].

Output

For each test case, output one line containing Case #x: K is ruled by Y., where x is the case number (starting from 1), K is the kingdom name, and Y is either Alice, Bob or nobody.

Be careful with capitalization and the terminating period. Your output must be in exactly this format. See the examples below.

Limits

Time limit: 30 seconds.
Memory limit: 1 GB.
1≤T≤300

/* Sample Input
3
Mollaristan
Auritania
Zizily
*/

/* Sample Output
Case #1: Mollaristan is ruled by Bob.
Case #2: Auritania is ruled by Alice.
Case #3: Zizily is ruled by nobody.
*/

import java.util.Scanner;

public class CentauriPrime {
    static String[] vowels = new String[]{"A", "E", "I", "O", "U", "a", "e", "i", "o", "u"};

    private static String getRuler(String kingdom) {
        // TODO: implement this method to determine the ruler name, given the kingdom.
        String ruler = "";

        if(kingdom.endsWith("Y") || kingdom.endsWith("y")) {
            ruler = "nobody";
        }

        if(ruler.isEmpty()) {
            for (String vowel : vowels) {
                if (kingdom.endsWith(vowel)) {
                    ruler = "Alice";
                    break;
                }
            }
        }

        if(ruler.isEmpty()) {
            ruler = "Bob";
        }

        return ruler;
    }

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int T = in.nextInt();

            for (int t = 1; t <= T; ++t) {
                String kingdom = in.next();
                System.out.println(
                        "Case #" + t + ": " + kingdom + " is ruled by " + getRuler(kingdom) + ".");
            }
        }
    }
}
profile
This is titu

0개의 댓글