View Code of Problem 56

#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node{
	int a,b,c;
}s[3];
int cmp(node m,node n){
	   if(m.a!=n.a) return m.a>n.a;
	   else {
	   	     if(m.b!=n.b) return m.b>n.b;
	   	     else    return m.c>n.c;
	   }
	   
}
int main(){
	for(int i=0;i<2;i++){
		scanf("%d:%d:%d", &s[i].a,&s[i].b,&s[i].c);
	}
      sort(s,s+2,cmp);
      s[2].c=s[0].c-s[1].c;
      if(s[2].c<0) {
      	s[2].c+=60; s[0].b--;
	  }
	  s[2].b=s[0].b-s[1].b;
	  if(s[2].b<0){
	  	s[2].b+=60; s[0].a--;
	  }
      s[2].a=s[0].a-s[1].a;
                  printf("%d:", s[2].a);
	      if(s[2].b<10) printf("0%d:",s[2].b);
	      else          printf("%d:", s[2].b);
	      if(s[2].c<10) printf("0%d\n", s[2].c);
	      else          printf("%d\n", s[2].c);
       
	  return 0;
}

Double click to view unformatted code.


Back to problem 56