View Code of Problem 56

#include<stdio.h>
#include<string.h>
int main()
{
	int h1,m1,s1;
	int h2,m2,s2;
	int h,m,s;
	scanf("%d:%d:%d",&h1,&m1,&s1);
	scanf("%d:%d:%d",&h2,&m2,&s2);
	if (h1>h2)
		h=h1-h2;
	else
		h=h2-h1;
	if(m1>m2)
		m=m1-m2;
	else
		m=m2-m1;
	if(s1>s2)
		s=s1-s2;
	else
		s=s2-s1;
	if(m<10&&s<10)
		printf("%d:0%d:0%d\n",h,m,s);
	else if(m<10)
		printf("%d:0%d:%d\n",h,m,s);
	else if(s<10)
		printf("%d:%d:0%d\n",h,m,s);
	else
		printf("%d:%d:%d",h,m,s);
	
	return 0;
}

Double click to view unformatted code.


Back to problem 56