View Code of Problem 56

#include <stdio.h>
#include <string.h>
#include <math.h>
#define N 100
int main() {
	int s1, f1, m1;
	int s2, f2, m2;
	int a, b, c;
	scanf("%d:%d:%d", &s1, &f1, &m1);
	scanf("%d:%d:%d", &s2, &f2, &m2);
	if (s1 * 3600 + f1 * 60 + m1 > s2 * 3600 + f2 * 60 + m2) {
		a = s1 - s2, b = f1 - f2, c = m1 - m2;
		if (c < 0) {
			c += 60;
			b--;
		}
		if (b < 0) {
			b += 60;
			a--;
		}
	}
	else {
		a = s2 - s1, b = f2 - f1, c = m2 - m1;
		if (c < 0) {
			c += 60;
			b--;
		}
		if (b < 0) {
			b += 60;
			a--;
		}
	}




	printf("%d:%02d:%02d", a, b, c);

}

Double click to view unformatted code.


Back to problem 56