Rahul is a very busy person he doesn't want to waste his time. He keeps account of the duration of each and every work. Now he doesn't even get time to calculate the duration of works, So your job is to count the durations for each work and give it to Rahul.
Example:
Input: hs = 1, ms = 44, he = 2, me = 14
Output: 0 30
Approach
Java
public class Duration {public static void main(String[] args) {int hs = 1, ms = 44, he = 2, me = 14;duration(hs, ms, he, me);}static void duration(int hs, int ms, int he, int me) {int h = he - hs;int m = me - ms;if (m < 0) {h = h - 1;m = m + 60;}System.out.println(h + " " + m);}}
C++
#include <bits/stdc++.h>using namespace std;void duration(int hs, int ms, int he, int me){int h = he - hs;int m = me - ms;if (m < 0){h = h - 1;m = m + 60;}cout << h << " " << m << "\n";}int main(){int hs = 1, ms = 44, he = 2, me = 14;duration(hs, ms, he, me);return 0;}
No comments:
Post a Comment