题目描述
题目分析
输入为毫秒,故我们可以先将毫秒转化为秒,由于只需要输出时分,我们只需要将天数去除即可,可以在这里多训练一次天数判断
cpp
#include<bits/stdc++.h>
using namespace std;
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool is_ren(int n)
{
if((n % 100 != 0 && n % 4 == 0) || n % 400 == 0)return true;
return false;
}
int main()
{
long long x;
cin >> x;
x /= 1000;
//一天有24 * 60 * 60 = 86400 秒
bool flag = 0;
for(int i = 1970; ; i ++)
{
if(is_ren(i))m[2] = 29;
else m[2] = 28;
for(int j = 1; j <= 12; j ++)
{
for(int k = 1; k <= m[j]; k ++)
{
if(x >= 86400)
{
k ++;
x -= 86400;
}
else
{
flag = 1;
break;
}
}
if(flag)break;
}
if(flag)break;
}
int a = x / 3600;
int b = x % 3600 / 60;
int c = x % 60;
printf("%02d:%02d:%02d", a, b, c);
return 0;
}
但显然没必要,可以这样
cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long x;
cin >> x;
x /= 1000;
//一天有24 * 60 * 60 = 86400 秒
while(x >= 86400)x -= 86400;
int a = x / 3600;
int b = x % 3600 / 60;
int c = x % 60;
printf("%02d:%02d:%02d", a, b, c);
return 0;
}