时间转换
Description
输入一个整数 t,请你计算当天从 00:00:00 开始经过 t 秒以后的时间。
输出的格式按照 12 小时制输出:
如果时间在中午 12:00:00 之前,那么输出hh:mm:ss am,如果时间在 12:00:00 - 下午 01:00:00 之间,那么输出 hh:mm:ss midnoon,如果时间在下午 01:00:00 之后,输出hh:mm:ss pm。其中hh表示小时,mm表示分钟,ss表示秒数。注意,如果不足两位,前面用 0 代替。
Input
输入一个整数 t(0 <= t < 86400) 表示当经过的秒数。
Output
按照题目要求格式输出一行。
Sample Input 1
43201
Sample Output 1
12:00:01 midnoon
Sample Input 2
50000
Sample Output 2
01:53:20 pm
Source
计蒜客
代码:
#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
int main(){
int t;
cin>>t;
int hh,mm,ss,amp;
hh=t/3600;
mm=t%3600/60;
ss=t%60;
if(hh>12){
hh-=12;
}
else{
}
if(t<12*3600){
printf("%02d:%02d:%02d am",hh,mm,ss);
}
else if(t>13*3600){
printf("%02d:%02d:%02d pm",hh,mm,ss);
}
else{
printf("%02d:%02d:%02d midnoon",hh,mm,ss);
}
return 0;
}