View Code of Problem 56

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<string>
#include<set>
using namespace std;

int main(void){
	int h1,h2,m1,m2,s1,s2,h3,m3,s3;
	scanf("%d:%d:%d",&h1,&m1,&s1);	
	scanf("%d:%d:%d",&h2,&m2,&s2);
	int temp;
	if(h1<h2||(h1==h2&&m1<m2)||(h1==h2&&m1==m2&&s1<s2)){
		temp = h1;
		h1 = h2;
		h2 = temp;
		
		temp = m1;
		m1 = m2;
		m2 = temp;
		
		temp = s1;
		s1 = s2;
		s2 = temp;
	}
	
	h3 = h1 - h2;
	m3 = m1 - m2;
	s3 = s1 - s2;
	if(s3<0){
		s3+=60;
		m3--;
	}
	if(m3<0){
		m3+=60;
		h3--;
	}
	
	if(m3>=10&&s3>=10)
		printf("%d:%d:%d",h3,m3,s3);
	else if(m3<10&&s3>=10)
		printf("%d:0%d:%d",h3,m3,s3);
	else if(m3>=10&&s3<10)
		printf("%d:%d:0%d",h3,m3,s3);
	else if(m3<10&&s3<10)
		printf("%d:0%d:0%d",h3,m3,s3);
}

Double click to view unformatted code.


Back to problem 56