题目链接:Click here
思路:直接模拟。去年在现场没做出来,对此心里一直有一个疙瘩。
话不多说, 看代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cstdlib>
using namespace std;
struct node
{
int h, m, s;
int states;
} q[50]; //储存每道题目的信息
int main()
{
int n, sh, sm, ss, n2, k;
int a, b, c, tem, ans1, ans2, ans3;
char que[3], sta[5], x1, x2;
scanf("%d", &n);
while(n--)
{
scanf("%d%c%d%c%d", &sh, &x1, &sm, &x2, &ss);
scanf("%d", &n2);
for(int i = 0; i < 20; i++)
{//初始化
q[i].states = 0;
q[i].h = q[i].m = q[i].s = 0;
}
for(int i = 0; i < n2; i++)
{
scanf("%s%d%c%d%c%d%s", que, &a, &x1, &b, &x2, &c, sta);
k = que[0] - 'A';
if(q[k].states == 0)
{
if(sta[0] != 'A')
q[k].m += 20;
else
{
a--;
b += 59; //这里都向下借一个单位,防止减成负数
c += 60;
q[k].h += a - sh;
q[k].m += b - sm;
q[k].s += c - ss;
q[k].states = 1;
}
}
}
ans1 = ans2 = ans3 = 0;
for(int i = 0; i < 20; i++)
{
if(q[i].states == 1)
{
ans1 += q[i].h;
ans2 += q[i].m;
ans3 += q[i].s;
}
}
tem = ans3;
ans3 = tem % 60;
ans2 += tem / 60;
tem = ans2; //按照时间的表示规则,将其换算
ans2 = tem % 60;
ans1 += tem / 60;
printf("%02d:%02d:%02d\n", ans1, ans2, ans3);
}
return 0;
}