알고리즘/[코드업] 기초3. if ~ else
[JAVA] CodeUp 1204 : 영어 서수로 표현하기
Art Rudy
2021. 8. 6. 12:27
728x90
반응형
https://codeup.kr/problem.php?id=1204
영어 서수로 표현하기
영어로 서수를 표현할 때 다음과 같이 나타낸다. 1st 2nd 3rd 4th 5th 6th ... 10th 11th 12th 13th 14th 15th ... 20th 21st 22nd 23rd 24th 25th ... 30th 31st 32nd 33rd 34th 35th ... 40th 41st 42nd 43rd 44th 45th ...
codeup.kr
문제 분류 : 기초3. if ~ else
문제 설명
영어로 서수를 표현할 때 다음과 같이 나타낸다.
1st 2nd 3rd 4th 5th 6th ... 10th
11th 12th 13th 14th 15th ... 20th
21st 22nd 23rd 24th 25th ... 30th
31st 32nd 33rd 34th 35th ... 40th
41st 42nd 43rd 44th 45th ... 50th
...
91st 92nd 93rd 94th 95th ... 99th
1~99 중 하나가 숫자가 입력되면 영어 서수 표현을 출력하시오.
입력
1~99 중 한 정수가 입력된다.
출력
입력된 정수의 영어 서수 표현을 출력한다.
입력 예시
2
출력 예시
2nd
도움말
내 답안
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int a = Integer.parseInt(br.readLine());
String result = null;
if(a==1 || a%10==1) {
if(a==11) {
result = "th";
}else {
result = "st";
}
}else if(a==2 || a%10==2) {
if(a==12) {
result = "th";
}else {
result = "nd";
}
}else if(a==3 || a%10==3) {
if(a==13) {
result = "th";
}else {
result = "rd";
}
}else {
result = "th";
}
bw.write(String.valueOf(a)+result);
bw.flush();
bw.close();
br.close();
}
}
728x90
반응형