HNUST 1641 罚时计算器(模拟) 湖南科技大学2014新生选拔赛

题目链接: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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值