cheng_you_know

学而时习之!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#include <iostream>
#include <stdlib.h>
using namespace std;
typedef struct MY_TIME
{
    int HH;
    int MM;
    int SS;
}MY_TIME;
int main()
{
    int n,i;
    MY_TIME current_time,back_time;
    char s1[50],s2[50];
    int current_total;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%s %s",s1,s2);
            sscanf(s1,"%d:%d:%d",&current_time.HH,&current_time.MM,&current_time.SS);
            sscanf(s2,"%d:%d:%d",&back_time.HH,&back_time.MM,&back_time.SS);
            back_time.HH = back_time.HH % 12;
            current_total = (current_time.HH *3600 + current_time.MM*60 + current_time.SS) -(back_time.HH *3600 + back_time.MM*60 + back_time.SS);
            if(current_total < 0)
                current_total +=12*3600; //注意是12小时制的时间,刚开始搞成24小时了
            current_time.HH = current_total/3600;
            current_time.MM = (current_total - current_time.HH *3600)/60;
            current_time.SS = current_total - current_time.HH*3600 - current_time.MM*60;
            printf("%02d:%02d:%02d\n",current_time.HH,current_time.MM ,current_time.SS);
        }
    }
    return 0;
}
posted on 2013-07-13 18:59  cheng_you_know  阅读(125)  评论(0编辑  收藏  举报