#include <stdio.h> typedef struct tm{ int hour,munite,second; }tm; int comp(const void* a,const void* b) { tm* c = (tm*)a; tm* d = (tm*)b; if(c->hour == d->hour) { if(c->munite == d->munite) return d->second - c->second; else return d->munite - c->munite; } else return d->hour - c->hour; } int main(void) { tm a[2]; int i; for(i = 0;i < 2;i++) { scanf("%d:%d:%d",&a[i].hour,&a[i].munite,&a[i].second); } qsort(a,2,sizeof(tm),comp); int s,m,h; s = a[0].second - a[1].second; if(h < 0) { s += 60; a[0].munite--; } m = a[0].munite - a[1].munite; if(m < 0) { m += 60; a[0].hour--; } h = a[0].hour - a[1].hour; if(m < 10 && s < 10) printf("%d:0%d:0%d\n",h,m,s); else if(m < 10 && s >= 10) printf("%d:0%d:%d\n",h,m,s); else if(m >= 10 && s < 10) printf("%d:%d:0%d\n",h,m,s); else printf("%d:%d:%d\n",h,m,s); return 0; } |
Double click to view unformatted code.