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);
}
}
'백준 > 10001 - 15000' 카테고리의 다른 글
[백준] 13417번 : 카드 문자열(JAVA) (0) | 2021.08.07 |
---|---|
[백준] 12931번 : 두 배 더하기(JAVA) (0) | 2021.08.04 |
[백준] 11117번 : Letter Cookies(JAVA) (0) | 2021.08.03 |
[백준] 10815번 : 숫자 카드(JAVA) (0) | 2021.08.01 |
[백준] 12107번 : 약수 지우기 게임1(JAVA) (0) | 2021.07.29 |
댓글