标签:turn sharp 导致 test name time contest c代码 数字
题意:给出时间和时区,转换成UTC+8的时间
思路:将所有的时间都转换成分钟,输出用%02d,可是当时卡在了精度上面
double mm=off*60.0-480.0将时间偏差转化成分钟
mm转化成整数时,由于精度损失,1.0可能被表示成0.99999,导致1.0变成0(一般精度损失是减小原数字)
特别注意:当mm为正数时,需要将mm先加0.00001,而mm为负数是应该减掉0.00001
ac代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int T,h,m;
double off;
cin>>T;
while(T--)
{
scanf("%d %d UTC%lf",&h,&m,&off);
double mm=off*60.0-480.0;
int mk;
if(mm>0)mk=mm+0.0001;
else mk=mm-0.0001;
int now=h*60+m+mk;
if(now>=0)now%=(24*60);
else now+=(24*60);
printf("%02d:%02d\n",now/60,now%60);
}
return 0;
}
2018 Multi-University Training Contest 1
标签:turn sharp 导致 test name time contest c代码 数字
原文地址:https://www.cnblogs.com/carcar/p/9487880.html