https://www.hackerrank.com/challenges/the-time-in-words/problem
배열로 변환할 문자열들 선언해두기
m은 30까지, h는 12까지 필요하므로 한 배열에 30까지 두기 (quarter로 인해 15를 뺀다고 생각할 수 있으나 나머지 계산이 힘들어지므로 넣기)
첫번째 요소는 blank로 설정 (편의)
조건에 맞춰서 출력해줌 (m == 0, m == 15, m== 30, m == 45, m == 59, m ==1, m<=30, m>30)
#define _CRT_SECURE_NO_WARNINGS
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Complete the timeInWords function below.
char* arr[] = { "blank","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"
,"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"
, "twenty one", "twenty two", "twenty three", "twenty four", "twenty five", "twenty six", "twenty seven", "twenty eight", "twenty nine" };
char* timeInWords(int h, int m)
{
if (m == 0)
printf("%s o' clock", arr[h]);
else if (m <= 30)
{
if (m == 1)
printf("%s minute past %s", arr[m], arr[h]);
else if (m == 15)
printf("quarter past %s", arr[h]);
else if (m == 30)
printf("half past %s", arr[h]);
else
printf("%s minutes past %s", arr[m], arr[h]);
}
else if (m > 30)
{
if (m == 59)
printf("%s minute to %s", arr[0], arr[h + 1]);
else if (m == 45)
printf("quarter to %s", arr[h + 1]);
else
printf("%s minutes to %s", arr[60 - m], arr[h + 1]);
}
return 0;
}
int main()
{
int h, m;
scanf("%d\n%d", &h, &m);
timeInWords(h, m);
return 0;
}