본문 바로가기

Algorithm/String

(C++) - 백준(BOJ) 12518번 : Centauri Prime (Small2)

반응형

https://www.acmicpc.net/problem/12518

 

12518번: Centauri Prime (Small2)

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 quee

www.acmicpc.net

문자열 다루는 문제였습니다.

 

* 나라이름이 최대 100글자이므로 1글자인 나라의 경우 대문자이자 마지막 글자가 될 수 있습니다. 따라서 대문자인 경우도 확인해줘야합니다.

 

📕 Code

#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int testCase, cnt;
int main(){
    fastio;
    cin >> testCase;
    for(cnt = 1; cnt <= testCase; cnt++){
        char s[101], lastChar, k[10];
        cin >> s;

        lastChar = s[strlen(s)-1];
        if(lastChar == 'y' || lastChar == 'Y') strcpy(k,"nobody");

        else if(
            lastChar == 'a' || 
            lastChar == 'e' || 
            lastChar == 'i' || 
            lastChar == 'o' || 
            lastChar == 'u' ||
            lastChar == 'A' || 
            lastChar == 'E' || 
            lastChar == 'I' || 
            lastChar == 'O' || 
            lastChar == 'U'
        ) strcpy(k,"a queen");

        else strcpy(k,"a king");
        
        printf("Case #%d: %s is ruled by %s.\n", cnt, s, k);
    }
}