View Code of Problem 56

#include<bits/stdc++.h>
using namespace std;



int main() {

	int h1,m1,s1,h2,m2,s2;
	while(scanf("%2d:%2d:%2d",&h1,&m1,&s1)!=EOF){
		scanf("%2d:%2d:%2d",&h2,&m2,&s2);
		int num1,num2;
		num1=h1*60*60+m1*60+s1;
		num2=h2*60*60+m2*60+s2;
		if(num1>num2){
			swap(num1,num2);
		}
		int num=num2-num1;
		int h3,m3,s3;
		h3=num/60/60;
		m3=(num-h3*60*60)/60;
		s3=(num-h3*60*60-m3*60);
		printf("%d:%02d:%02d\n",h3,m3,s3); 
	}
	
	
	return 0;
}

Double click to view unformatted code.


Back to problem 56