View Code of Problem 56

# include<stdio.h>
void addZero(int x){
	if(x<10){
		printf(":0%d",x);
	}
	else{
		printf(":%d",x);
	}
}
int main(){
	int xh,xm,xs,yh,ym,ys;
	scanf("%d:%d:%d",&xh,&xm,&xs);
	scanf("%d:%d:%d",&yh,&ym,&ys);
	int x1=xh*3600+xm*60+xs;
	int x2=yh*3600+ym*60+ys;
	if(x1>x2){
		int temp=x1;
		x1=x2;
		x2=temp;
	} 
	int x=x2-x1;
	int h=x/3600;
	int m=(x%3600)/60;
	int s=(x%3600)%60;
	printf("%d",h);
	addZero(m);
	addZero(s);
	return 0;
}

Double click to view unformatted code.


Back to problem 56