title:
Sometimes people use four digits said a time, such as 1106 indicates zero 6 points, 11 o 'clock now, your program according to the beginning of the passage of time and calculate the termination time,
Reads in two Numbers, the first number in this four figures show that the current time, the second number said minutes, calculate the current time is what time after so many minutes later, the results are represented by four digits, when hours for single digits, without leading zeros, such as 5 a.m. is expressed as 530; 0 a.m. is expressed as 030, note that the number of minutes of said second number may be more than 60, may also be negative,
Input format:
Input in one line gives two integers, respectively is the start time of four digital representation, and passed on the number of minutes, during which separated by Spaces, note: in the starting time, when the hour is single, without leading zeros, namely 5 a.m. is expressed as 530; 0 a.m. is expressed as 030, passed the number of minutes may be more than 60, may also be negative,
The output format:
Output four-digit said termination time, when the hour is single digits, there is no leading zero, title guarantee the starting time and ending time on the same day,
Input the sample:
1120, 110,
The output sample:
1310
# include "stdio.h"
Int main ()
{
Int num1, num2;
The scanf (" % d % d ", & amp; Num1, & amp; Num2);
Int h=num1/100;
Int m=num1%100;
Int h1=num2/60;
Int m1=num2 - h1 * 60;
H +=h1;
M +=m1;
If (m & gt; 60)
{
H++;
M -=60;
}
If (h * 100 + m & gt;=0 & amp; & H * 100 + m & lt; 100)
Printf (" % 3 d, h * 100 + m);
The else
Printf (" % d ", h * 100 + m);
return 0;
}
CodePudding user response:
Said in the title, number of minutes of passage is likely to be negative, the building Lord you don't seem to have to consider,CodePudding user response:
I considered it?CodePudding user response:
# include & lt; Stdio. H>
#include
Int main ()
{
Int num1, num2, sign=0;
The scanf (" % d % d ", & amp; Num1, & amp; Num2);
Int h=num1/100;
Int m=num1%100;
If (num2 & lt; 0 {
Sign=1;
Num2=abs (num2);
}
Int h1=num2/60;
//int m1=num2 - h1 * 60;
Int m1=num2%60;
If (sign) {
If (m - m1 & lt; 0 {
M=m + 60 - m1;
H1 +=1;
} else {
M -=m1;
}
If (h - h1 & lt; 0)
H=h + 24 - h1;
The else
H=h - h1;
} else {
If (m + m1 & gt; 60) {
H=(h + h1 + 1) % 24;
M=(m + m1) % 60;
} else {
M=(m + m1) % 60;
H=(h + h1) % 24;
}
}
If (h * 100 + m & gt;=0 & amp; & H * 100 + m & lt; 100)
Printf (" % 3 d, h * 100 + m);
The else
Printf (" % d ", h * 100 + m);
/*
H +=h1;
M +=m1;
If (m & gt; 60)
{
H++;
M -=60;
}
If (h * 100 + m & gt;=0 & amp; & H * 100 + m & lt; 100)
Printf (" % 3 d, h * 100 + m);
The else
Printf (" % d ", h * 100 + m);
*/
return 0;
}
For your reference ~
CodePudding user response:
Well,Num2 if negative, large probability of m1 is negative;
M +=m1; Later, m is negative?
CodePudding user response: