View Code of Problem 56

#include<stdio.h>
void main(){
	int h1,m1,s1,h2,m2,s2,h,m,s,t1,t2,t3;
	scanf("%d:%d:%d",&h1,&m1,&s1);
	scanf("%d:%d:%d",&h2,&m2,&s2);
	if(h1>h2){
		t1=h1;
		h1=h2;
		h2=t1;
		t2=m1;
		m1=m2;
		m2=t2;
		t3=s1;
		s1=s2;
		s2=t3;
	}
	s=s2-s1;
	if(s<0){
		s=s+60;
		m2=m2-1;
	}
	m=m2-m1;
	if(m<0){
		m=m+60;
		h2=h2-1;
	}
	h=h2-h1;
	printf("%d:",h);
	if(m>=0&&m<=9)
		printf("0%d:",m);
	else
		printf("0%d:",m);
	if(s>=0&&s<=9)
		printf("0%d",s);
	else
		printf("%d",s);
}

Double click to view unformatted code.


Back to problem 56