B.Time | |||||
| |||||
Description | |||||
Kim是一个掌控时间的大师。不同于一般人,他习惯使用秒来计算时间。如果你问他现在是几点,他会告诉你现在是今天的xxxx秒。Mik想要考考Kim。他想知道从某一天的00:00:00开始,经过s秒后是哪一天。但是Mik不会计算答案,他需要你的帮助。 注意:我们认为一天从00:00:00开始,到23:59:59结束。00:00:00经过1秒后是00:00:01;从00:00:00开始,加86400(60*60*24)秒后就是下一天的00:00:00. | |||||
Input | |||||
第一行一个整数T表示数据组数。 接下来T行,每行一个日期yyyy-MM-dd,接下来一个整数s表示s秒。 | |||||
Output | |||||
对于每个输入,输出一行yyyy-MM-dd 表示答案。对于不足两位的数要补齐前导0。 | |||||
Sample Input | |||||
3 2016-12-10 1000 2016-02-28 86400 2016-01-01 1000000 | |||||
Sample Output | |||||
2016-12-10 2016-02-29 2016-01-12 | |||||
Hint | |||||
T<=100 s<=2147483647 日期在1800-01-01到2100-01-01之间
闰年的判断: 1.能被4整除且不能被100整除的为闰年. 2.能被400整除的是闰年.
|
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#define FOR(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
bool isleap(int y){
if ((y%4==0 && y%100!=0) || y%400==0) return true;
return false;
}
int maxday(int y,int m){
if (m==2){
if (isleap(y)) return 29;
else return 28;
}else{
if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) return 31;
else return 30;
}
}
int main (int argc, char *argv[])
{
int noc;int y,m,d;int s;
scanf("%d",&noc);
while (noc--){
scanf("%d-%d-%d%d",&y,&m,&d,&s);
int ad=s/86400.0;
FOR(_,1,ad){
d++;
if (d>maxday(y,m)){
d=1;
m++;
}
if (m==13){
m=1;
y++;
}
}
printf("%d-%.2d-%.2d\n",y,m,d);
}
return 0;
}