C language daily question - small music set the alarm clock (Nioke.com)

describe

Xiao Lele is lazy, he wants to sleep now, and then go to study. He knows the current time and how long he is going to sleep. He wants to set an alarm clock to wake him up to study, but he is too stupid to know when to set the alarm clock. Please help him. (Only hours and minutes are considered, not dates)

Enter description:

Enter the current time and the duration of sleep k (unit: minute), separated by spaces.

Input format: hour:minute k (if the value of hour or minute is 1, the input is 1, not 01)

(0 ≤ hour ≤ 23,0 ≤ minute ≤ 59,1 ≤ k ≤ 109)

Output description:

For each set of input, output the time when the alarm clock should be set, and the output format is the standard time notation (instant and minute are represented by two digits, and the number of digits is not enough to be filled with leading 0).

Example 1

enter:

0:0 100

output:

01:40

Example 2

enter:

1:0 200

output:
04:20
#include<stdio.h>
int main()
{
	int a, b, c, d;
	scanf("%d:%d %d", &a, &b, &c); //输入三个数字分别是起始的时 分和设定的时间长度,单位为分
	d = a + (b + c) / 60;      //(b+c)/60 将以分为单位的数值加起来转换为小时再+a即加上原来的时,d=最终的时位
	printf("%02d:%02d", d % 24,(60 * a + b + c - 60 * d)%60);//d%24对24取余防止超过24小时,60*a+b+c-60*d // 60*a将时位上的数转换位分,再+b+c将所有数字化为分,-60*d总分钟减去 时位上的时长,剩下的自然是分位的时长,对60取余,防止超过60
	return 0;
}

Note: Take the remainder of the time bit and the quantile to prevent it from exceeding 24 and 60

Guess you like

Origin blog.csdn.net/weixin_49449676/article/details/123981947