View Code of Problem 56

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include<vector>
#include<math.h>
using namespace std;
void swap(int *x, int *y) {
	int t;
	t = *x;
	*x = *y;
	*y = t;
}
int main()
{
	int a, b, c;
	int d, e, f;
	scanf("%d:%d:%d", &a,&b,&c);
	scanf("%d:%d:%d", &d,&e,&f);
	if (a < d) {
		swap(a, d);
		swap(b, e);
		swap(c, f);
	}
	int g, h, i;
	if (c >= f) {
		i = c - f;
	}
	if (c < f) {
		b--;
		i = c + 60 - f;
	}
	if (b >= e) {
		h = b - e;
	}
	if (b < e) {
		a--;
		h = b + 60 - e;
	}
	g = a - d;
	cout << g << ":" << setw(2) << setfill('0') << h << ":" << setw(2) << setfill('0') << i ;
	//printf("%d:%02d:%02d\n", g, h, i);
}

Double click to view unformatted code.


Back to problem 56