/*
ID: ****
LANG: C
TASK: clock
*/
#define __DEBUG__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* itoc(int num);
int main()
{
char* temp;
char time[6];
int hour;
int min;
char out[100];
#ifndef __DEBUG__
FILE *fin;
FILE *fout;
fin = fopen("clock.in","r");
fout = fopen("clock.out","w");
fscanf(fin,"%s",time);
#else
printf("Input time : ");
scanf("%s",time);
#endif
temp = strtok(time,":");
hour = atoi(temp);
temp = strtok(NULL,":");
min = atoi(temp);
switch(min)
{
case 0:
sprintf(out,"%s o'clock",itoc(hour));
break;
case 15:
sprintf(out,"Quarter past %s",itoc(hour));
break;
case 45:
sprintf(out,"Quarter to %s",itoc(hour%12+1));
break;
default:
if(min>45)
sprintf(out,"%s to %s",itoc(60-min),itoc(hour%12+1));
else
sprintf(out,"%s %s",itoc(hour),itoc(min));
}
out[0]=toupper(out[0]);
#ifndef __DEBUG__
fprintf(fout,"%sn",out);
fclose(fin);
fclose(fout);
#else
printf("%sn",out);
#endif
return 0;
}
char* itoc(int num)
{
char* retval;
retval = (char*)malloc(sizeof(char)*20);
if(num<20)
{
switch(num)
{
case 1: return "one";
case 2: return "two";
case 3: return "three";
case 4: return "four";
case 5: return "five";
case 6: return "six";
case 7: return "seven";
case 8: return "eight";
case 9: return "nine";
case 10: return "ten";
case 11: return "eleven";
case 12: return "twelve";
case 13: return "thirteen";
case 14: return "fourteen";
case 15: return "fifteen";
case 16: return "sixteen";
case 17: return "seventeen";
case 18: return "eighteen";
case 19: return "nineteen";
default: return "";
}
}
else
{
switch(num/10)
{
case 2:
sprintf(retval,"twenty");
break;
case 3:
sprintf(retval,"thirty");
break;
case 4:
sprintf(retval,"forty");
break;
case 5:
sprintf(retval,"fifty");
break;
}
switch(num%10)
{
case 0:
break;
case 1:
strcat(retval,"-one");
break;
case 2:
strcat(retval,"-two");
break;
case 3:
strcat(retval,"-three");
break;
case 4:
strcat(retval,"-four");
break;
case 5:
strcat(retval,"-five");
break;
case 6:
strcat(retval,"-six");
break;
case 7:
strcat(retval,"-seven");
break;
case 8:
strcat(retval,"-eight");
break;
case 9:
strcat(retval,"-nine");
break;
}
}
return retval;
}
상당히 간단한 문제였다.
'Developing' 카테고리의 다른 글
PERL에서의 웹 프로그래밍 (0) | 2006.06.03 |
---|---|
USACO Training - Barn Repair (0) | 2006.05.09 |
USACO Training - Mixing Milk (0) | 2006.05.03 |