본문 바로가기

Algorithm/String

(C++) - 백준(BOJ) 12517번 : Centauri Prime (Small1)

반응형

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

 

12517번: Centauri Prime (Small1)

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

단순 string 문제였습니다.

* a 유무 조심

 

📕 Code

#include <bits/stdc++.h>
using namespace std;
char s[30];
int testCase, cnt;
int main(){
    cin >> testCase;
    while(cin >> s){
        cnt++;
        char lastChar, k[10];
        lastChar = s[strlen(s)-1];
        if(lastChar == 'y') strcpy(k,"nobody");

        else if(
            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);
    }
}