#include<stdio.h> int main() { int h1,h2,m1,m2,n1,n2,x,y,z,s; scanf("%d:%d:%d",&h1,&m1,&n1); scanf("%d:%d:%d",&h2,&m2,&n2); /*if(h2*3600 + m2 * 60 + n2 - h1 * 3600 - m1 * 60 - n1 > 0) { x = h2 - h1; y = m2 - m1; z = n2 - n1; if(y < 0) { y = y + 60; x--; } if(z < 0) { z = z + 60; y--; } } else { x = h1 - h2; y = m1 - m2; z = n1 - n2; if(y < 0) { y = y + 60; x--; } if(z < 0) { z = z + 60; y--; } }*/ s = h2*3600 + m2 * 60 + n2 - h1 * 3600 - m1 * 60 - n1; if(s > 0) { x = s / 3600; y = (s % 3600) / 60; z = (s % 3600) % 60; } else { x = (-s) / 3600; y = ((-s) % 3600) / 60; z = ((-s) % 3600) % 60; } printf("%d:%02d:%02d",x,y,z); return 0; } |
Double click to view unformatted code.