Home > Back-end >  According to the train departure time and arrival time, write the time required for the whole journe
According to the train departure time and arrival time, write the time required for the whole journe

Time:10-25

Input in a row in two of the four positive integers, that said the train arrival and departure time, every time format for 2 hours (00-23) and two minutes (00-59) assumes that the departure and arrival on the same day, how do you write this program

CodePudding user response:



Int sTime eTime; Start time and arrival time

Split the hour and minute
Int sH, sM, eH, eM.
SH=sTime/100; SM=sTime % 100;
EH=eTime/100; EM=eTime % 100;

If (eMNumber of minutes of use: eM + 60 - sM
With the number of hours: eH - sH - 1;//be on minutes an hour where borrowed
} else {
Number of minutes of use: eM - sM;
With the number of hours: eH - sH;
}

Code written by yourself, don't know what is your required output format

CodePudding user response:

Fun
reference 1 floor response:
int sTime, eTime. Start time and arrival time

Split the hour and minute
Int sH, sM, eH, eM.
SH=sTime/100; SM=sTime % 100;
EH=eTime/100; EM=eTime % 100;

If (eMNumber of minutes of use: eM + 60 - sM
With the number of hours: eH - sH - 1;//be on minutes an hour where borrowed
} else {
Number of minutes of use: eM - sM;
With the number of hours: eH - sH;
}

Code written by yourself, also don't know you ask what is the output format of

This can be in any specific point a little look not to understand

CodePudding user response:


Start time sTime 1220 apart sH=12 (12 hours), sM=20 (20 minutes)
End time eTime eH=13 1404 apart, eM=4

Em is smaller than sM, not directly do subtraction, so be borrowed from hours there for an hour, which is 60 minutes, into 60 + 4=64 minus 20, is 44 minutes
And then eH - sH - 1 is 14-12-1=1
Takes 1 hour and 44 minutes

CodePudding user response:

After open eTime1404, eH=14 ha

He is, so the gap minutes is not enough, borrowed an hour bai, an hour is 60 minutes

CodePudding user response:

Fun
reference 4 floor response:
apart eTime1404, eH=14 after ha

He is, so the gap minutes is not enough, borrowed an hour bai, an hour is 60 minutes

Hello can you help me take a look at this program, please this is the answer to this question is a little look not to understand
#include
Intmain ()
{
Intks, js, xs, fz.
The scanf (" % d % d ", & amp; Ks, & amp; Js);
Xs=js/100 - ks/100;
Fz=js % 100 - ks % 100;
If (fz<0 {xs=xs - 1; Fz=60 + fz. }
02 02 printf (" % d: % d ", xs, fz);
Return0;
}

CodePudding user response:

Int main ()
{
Intks, js, xs, fz.
The scanf (" % d % d ", & amp; Ks, & amp; Js);//ks start time, end of js time
Xs=js/100 - ks/100;//js/100 extraction is the arrival time is what time, arrived in 1404, 1404/100 is 14; This is to calculate the jet lag
Fz=js % 100 - ks % 100;//js % 100 is to extract the end time is a few minutes, reached 1404, 1404% of 100 is 4; This is to calculate the gap
If (fz<0 {xs=xs - 1; Fz=60 + fz. }//is in the judgment, insufficient points do subtraction on the bottom; If not borrowed an hour less than
02 02 printf (" % d: % d ", xs, fz);
Return0;
}
The idea is no difference between

The key is you want to understand, don't have a computer, you use head and how to calculate, the computer implementation, it's the thoughts in your mind filled with
Don't need to be like other people's ideas, as long as you think of can

CodePudding user response:

Fun
reference 6 floor response:
int main ()
{
Intks, js, xs, fz.
The scanf (" % d % d ", & amp; Ks, & amp; Js);//ks start time, end of js time
Xs=js/100 - ks/100;//js/100 extraction is the arrival time is what time, arrived in 1404, 1404/100 is 14; This is to calculate the jet lag
Fz=js % 100 - ks % 100;//js % 100 is to extract the end time is a few minutes, reached 1404, 1404% of 100 is 4; This is to calculate the gap
If (fz<0 {xs=xs - 1; Fz=60 + fz. }//is in the judgment, insufficient points do subtraction on the bottom; If not borrowed an hour less than
02 02 printf (" % d: % d ", xs, fz);
Return0;
}
The idea is no difference between

The key is you want to understand, don't have a computer, you use head and how to calculate, the computer implementation, it's the thoughts in your mind filled with
Don't need to be like other people's ideas, as long as you think of can

Well well thank you
  • Related