题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6308
思路:输入的时候可以用sscanf(sscanf(s+4, "%lf", &x))从字符串读取格式化输入,也可以直接用scanf(scanf("%d %d UTC%c%lf",&h,&m,&ch,&x))直接格式化输入,然后全部转化为分钟计算。关于double精度问题,点我,点我。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int t, h, m; char s[10];
cin >> t;
while(t--)
{
scanf("%d%d%s", &h, &m, s);
h = h * 60 + m;
int op = s[3]=='+'?1:-1;
double x;
sscanf(s+4, "%lf", &x);
x = (int)(x*10 + 0.005); //防止精度损失
int cha = x*6*op - 8*60;
h += cha;
h = (h + 24*60) % (24*60);
printf("%02d:%02d\n", h/60, h%60);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int t, h, m;
char s[10], ch;
double x; cin >> t;
while(t--)
{
scanf("%d %d UTC%c%lf", &h,&m,&ch,&x);
h = h * 60 + m;
int op = ch == '+' ? 1 : -1;
x = (int)(x*10 + 0.005); //防止精度损失
int cha = x*6*op - 8*60;
h += cha;
h = (h + 24*60) % (24*60);
printf("%02d:%02d\n", h/60, h%60);
}
return 0;
}