View Code of Problem 56

#include <stdio.h>
int main(){
	int a[3],b[3];
	scanf("%d:%d:%d",&a[0],&a[1],&a[2]);
	scanf("%d:%d:%d",&b[0],&b[1],&b[2]);
	if(a[0]<b[0]){
		int i,t;
		for(i=0;i<3;i++){
			t=a[i];
			a[i]=b[i];
			b[i]=t;
		}
	}
	int h,m,s;
	h=a[0]-b[0];
	m=a[1]-b[1];
	s=a[2]-b[2];
	if(m<0){
		h--;
		m=m+60;
	}
	if(s<0){
		m--;
		s=s+60;
	}
	printf("%d:%02d:%02d",h,m,s);
		
	return 0;
}

Double click to view unformatted code.


Back to problem 56