Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

코딩로그

[백준/BOJ/C++] 12517번 Centauri Prime (Small1) 본문

YJ/C++

[백준/BOJ/C++] 12517번 Centauri Prime (Small1)

Team DAON 2021. 11. 2. 17:29

[문제]

Back in the old days before the creation of the mighty Centauri Republic, the planet Centauri Prime was split into several independent kingdoms. The kingdom of Mollaristan was ruled by king Loatold, while the kingdom of Auritania was under the rule of queen Elana. In fact, it just so happened that every kingdom whose name ended in a consonant was ruled by a king, while every kingdom whose name ended in a vowel was ruled by a queen. Also because of an amazing coincidence, all kingdoms whose named ended in the letter 'y' were constantly in a state of turmoil and were not ruled by anyone. Can you write a program that will determine the current rulers of several countries, given the countries' names?

[입력]

The first line of the input gives the number of test cases, T. T lines follow, each one containing the name of one country. Country 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.

Limits

  • 1 ≤ T ≤ 300.
  • Each country name will have between 3 and 20 letters.

[출력]

For each test case, output one line containing "Case #x: C is ruled by Y.", where x is the case number (starting from 1), C is the country name, and Y is either "a king", "a queen" or "nobody".

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

[Source Code]

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;


int main() {
	int test;
	cin >> test;

	int *result = new int[test];
	string *namearr = new string[test];
	for(int i = 0; i < test; i++){
		string name;
		cin >> name;
		namearr[i] = name;
		if(name[name.length()-1] == 'y')
			result[i] = 3;
		else if(name[name.length()-1] == 'a'||
			name[name.length()-1] == 'e'||
			name[name.length()-1] == 'i'||
			name[name.length()-1] == 'o'||
			name[name.length()-1] == 'u')
				result[i] = 2;
		else
			result[i] = 1;
	}

	for(int i = 0; i < test; i++){
		cout << "Case #" << i+1 << ": "<<namearr[i]<< " is ruled by ";
		if(result[i] == 1)
			cout << "a king.\n";
		else if(result[i] == 2)
			cout << "a queen.\n";
		else
			cout << "nobody.\n";
	}
}

[결과 화면]