- codewithshiva

Latest

Search Bar

Friday, July 2, 2021

 Count Duration

Description

Given 4 variables SH,SM,EH and EM  each separated by space(SH=starting hr, SM=starting min, EH=ending hr, EM=ending min), calculate and print the difference between the two times

Input

Input Format

First line will be given by N test cases

Next N line will be given SH,SM,EH and EM  each separated by space(SH=starting hr,SM=starting min, EH=ending hr, EM=ending min)

Constraints

N < 100

Output

Output Format

N lines with duration HH MM(hours and minutes separated by space)

Sample Input 1 

2
1 44 2 14
2 42 8 23

Sample Output 1

0 30
5 41

Hint

1:44 PM and 2:14 PM, this is 30 mins difference, so 0 hours 30 mins.

2:42 PM and 8:23 PM, this is 341 mins difference, so 5 hours 41 mins.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int redo= sc.nextInt();
for (int i =0 ;i<redo;i++){
int []array= new int[4];
for (int j=0;j<4;j++){
array[j]=sc.nextInt();
}
int hour=array[2]-array[0];
int min=array[3]-array[1];
if (min<0 && array[3]<array[1]){
min=60+min;
hour=hour-1;
}
System.out.println(hour+" "+min);
}

}
}

No comments:

Post a Comment