본문 바로가기
백준/10001 - 15000

[백준] 12517, 12518, 12525, 12526번 : Centauri Prime(JAVA)

by lms0806 2021. 8. 4.
728x90
반응형

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

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

 

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

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

 

12525번: 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

 

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

 

12526번: 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

풀이

다 같은 문제같지만 조금씩 다릅니다.

12517 = 12525(소문자만), 12518 = 12526(대문자도)

주어진 문자의 가장 끝 글자가 y면 "nobody", 모음이면 "a queen" 아니면 "a king"을 넣어서 출력하면됩니다.

 

소스코드

12517, 12525

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int size = Integer.parseInt(br.readLine());
		
		StringBuilder sb = new StringBuilder();
		for(int i = 1; i <= size; i++) {
			String s = br.readLine().trim();
			
			sb.append("Case #").append(i).append(": ").append(s).append(" is ruled by ");
			char ch = s.charAt(s.length() - 1);
			if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
				sb.append("a queen");
			}
			else {
				sb.append(ch == 'y' ? "nobody" : "a king");
			}
			sb.append(".\n");
		}
		System.out.print(sb);
	}	
}

12518, 12526

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int size = Integer.parseInt(br.readLine());
		
		StringBuilder sb = new StringBuilder();
		for(int i = 1; i <= size; i++) {
			String s = br.readLine().trim();
			
			sb.append("Case #").append(i).append(": ").append(s).append(" is ruled by ");
			char ch = s.toLowerCase().charAt(s.length() - 1);
			if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
				sb.append("a queen");
			}
			else {
				sb.append(ch == 'y' ? "nobody" : "a king");
			}
			sb.append(".\n");
		}
		System.out.print(sb);
	}	
}

 

728x90
반응형

댓글