2014年初中竞赛试题(南海) 睡眠

题目

这里写图片描述


解题思路

模拟,【模拟的思路越简单明了越好(简单的题目!!!),否则就像我一样,Wonderful Answer(WA)】

代码

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std; 
int a,b,aa,bb,x,y; 
int main()
{
    freopen("sleep.in","r",stdin);
    freopen("sleep.out","w",stdout); 
    scanf("%d:%d",&a,&b); 
    scanf("%d:%d",&aa,&bb); 
    a-=aa; b-=bb; 
    if (b<0) b+=60,a-=1; //特殊情况
    if (a<0) a+=24; 
    if (a<=9) printf("0%d",a); else printf("%d",a); 
    printf(":"); 
    if (b<=9) printf("0%d",b); else printf("%d",b); 
}

猜你喜欢

转载自blog.csdn.net/qq_39897867/article/details/79842500
今日推荐