#include<bits/stdc++.h> using namespace std; int main(){ int h1,h2,m1,m2,s1,s2; int M1,M2,t; scanf("%d:%d:%d",&h1,&m1,&s1); scanf("%d:%d:%d",&h2,&m2,&s2); M1 = s1 + m1*60 + h1 * 60*60; M2 = s2 + m2*60 + h2 * 60*60; if(M1 > M2){ t = h1; h1 = h2; h2 = t; t = m1; m1 = m2; m2 = t; t = s1; s1 = s2; s2 = t; } int ds = 0; while(h2 > h1|| m2 > m1 || s2 > s1){ s1++; if(s1==60){ m1++; s1 = 0; } if(m1==60){ h1++; m1 = 0; } ds++; } int a,b,c; a = ds /3600; b = (ds - 3600*a)/60; c = ds - 3600*a - 60*b; printf("%d:%02d:%02d",a,b,c); return 0; } |
Double click to view unformatted code.