Problem E: 時間:24小時制轉12小時制
Time Limit: 1 Sec Memory Limit: 16 MBSubmit: 2473 Solved: 648
[Submit][Status][Web Board]
Description
編寫一個程序,把輸入的24小時制的時間,轉換12小時制的格式輸出。
Input
輸入爲一行。輸入爲24小時制的小時和分,都佔滿2個字符的位置,用“:”分隔。範圍是00:00~23:59。
Output
輸出爲12小時制的小時和分,都佔滿2個字符的位置,用“:”分隔,一個空格後跟“a.m.”(午前)或“p.m.”(午後)。
Sample Input
Sample Output
#include <stdio.h>
#include <stdlib.h>
int main()
{
int xs,fz,swxw=1;
scanf("%d:%d",&xs,&fz);
if(xs == 0)
{xs = 12;swxw = 1;}
else if(xs > 12)
{xs -= 12;swxw = 0;}
else if(xs < 12)
swxw = 1;
else if(xs == 12)
swxw = 0;
if(xs < 10)
printf("0%d:",xs);
else
printf("%d:",xs);
if(fz < 10)
printf("0%d ",fz);
else
printf("%d ",fz);
if(swxw == 0)
printf("p.m.\n");
else
printf("a.m.\n");
return 0;
}