7-2 然后是几点 (15point(s)).c

The original question is as follows :

7-2 然后是几点 (15point(s))

有时候人们用四位数字表示一个时间,比如1106表示11点零6分。现在,你的程序要根据起始时间和流逝的时间计算出终止时间。

读入两个数字,第一个数字以这样的四位数字表示当前时间,第二个数字表示分钟数,计算当前时间经过那么多分钟后是几点,结果也表示为四位数字。当小时为个位数时,没有前导的零,即5点30分表示为530。注意,第二个数字表示的分钟数可能超过60,也可能是负数。
输入格式:

输入在一行中给出2个整数,分别是四位数字表示的起始时间、以及流逝的分钟数,其间以空格分隔。注意:在起始时间中,当小时为个位数时,没有前导的零,即5点30分表示为530;流逝的分钟数可能超过60,也可能是负数。
输出格式:

输出四位数字表示的终止时间,当小时为个位数时,没有前导的零。题目保证起始时间和终止时间在同一天内。
输入样例:

1120 110

输出样例:

1310

Thinking:
To avoid carrying conversion between hours and minutes, you can enter a decimal number into a unified total number of minutes, find the beginning to the total time now, and then the total combination of time into hours and minutes.

在这里插入图片描述
代码如下:

//  date:2020/3/4
//  author:xiezhg5
#include <stdio.h>
int main(void)
{   int d1,d2,t1,t2,t;
    scanf("%d %d",&d1,&t1);
    t2=d1/100*60+d1%100;       //把输入的十进制数化成总的分钟数 
    t=t1+t2;                   //t从开始到现在总的分钟数 
    d2=t/60*100+t%60;          //把分钟数化成十进制数 
    printf("%d\n",d2);
    return 0;
} 
发布了30 篇原创文章 · 获赞 10 · 访问量 293

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/104661502
今日推荐