1204 영어 서수로 표현하기

문제

영어에서 서수를 나타낼 때 다음과 같이 나타낸다.

1st  2nd  3rd  4th  5th  6th  ... 

11th 12th 13th 14th 15th...

21st 22nd 23rd 24th 25th ...

31st 32nd 33rd 34th 35th...

41st 42nd 43rd 44th 45th...

...

91st 92nd 93rd 94th 95th ... 99th

1부터 99까지의 숫자가 입력되면 영어 서수 표현으로 출력하시오.


입력

1~99 중 자연수가 하나 입력된다.


출력

영어 서수로 출력한다. 위의 문제 참고.


입력 예시  

2


출력 예시

2nd


코드

#include <stdio.h>
    
int main(){    
    int num;
    scanf("%d", &num);
    
    switch(num%10){
         case 1:
             if(num/10==1) printf("%dth", num);              // 11, 12, 13은 th로 출력한다.
             else printf("%dst", num);
             break;
         case 2: 
             if(num/10==1) printf("%dth", num);
             else printf("%dnd", num);
             break;
         case 3:
             if(num/10==1) printf("%dth", num);
             else printf("%drd", num);
             break;
         default:
             printf("%dth", num);
    }
   
    return 0;
}

'Wargame > CodeUp' 카테고리의 다른 글

1361 별 계단 만들기  (0) 2019.08.12
1265 구구단 출력하기 1  (0) 2019.08.04
1226 이번 주 로또  (0) 2019.08.04
1158 특별한 공 던지기 2  (0) 2019.08.03
1180 만능 휴지통  (0) 2019.08.03