View Code of Problem 56

#include <stdio.h>
int main()
{
	int a, b, c, d, e, f, x, y, z;
	int sum;
	while(scanf("%d:%d:%d", &a, &b, &c) != EOF)
	{
		scanf("%d:%d:%d", &d, &e, &f);
		int sum1 = (a * 60 + b) * 60 + c;
		int sum2 = (d * 60 + e) * 60 + f;
		if(d >= a)
		{
			sum = sum2 - sum1;
		}
		else
			sum = sum1 - sum2;
		x = sum / 3600;
		y = (sum % 3600) / 60;
		z = sum - x * 3600 - y * 60;
		printf("%d:%02d:%02d\n", x, y, z);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 56