Rahul is a very busy persion he dont wan't to waste his time . He keeps account of duration of each and every work. Now he don't even get time to calculate duration of works, So your job is to count the durations for each work and give it to rahul.

Input:
  • First line will be given by N number of works
  • 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)
Output:
  • N lines with duration HH MM(hours and minutes separated by space)
SAMPLE INPUT
2
1 44 2 14
2 42 8 23
SAMPLE OUTPUT
0 30
5 41

Solution-

import java.util.*;
class Duration{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int hh=0;
        int mm=0;
        int[][] ans = new int[n][2]; //{ {1,2} {1,2} {1,2} {1,2}}
        for(int i=0;i<n;i++)
        {
            int sh=sc.nextInt();
            int eh=sc.nextInt();
            int sm=sc.nextInt();
            int em=sc.nextInt();
        

            if(eh>em)
            {
hh=(sm-sh)-1;
mm=60-eh+em;
ans[i][0] = hh;
ans[i][1] = mm;
            }
            else
            {

                hh=sm-sh;
             mm=em-eh;
               ans[i][0] = hh;
ans[i][1] = mm;
            }

        }

        for(int i=0;i<n;i++)
            System.out.println(ans[i][0]+" "+ans[i][1]);
    
        }
}

Post a Comment

Previous Post Next Post