#include<stdio.h> #include<string.h> struct time{ int h; int m; int s; }t1,t2,t3,temp; int main() { int i,j; scanf("%2d:%2d:%2d",&t1.h,&t1.m,&t1.s); scanf("%2d:%2d:%2d",&t2.h,&t2.m,&t2.s); if(t1.h>t2.h) { temp=t1; t1=t2; t2=temp; } if(t2.s>t1.s) { t3.s=t2.s-t1.s; } else { t3.s=t2.s+60-t1.s; if(t2.m>0) t2.m=t2.m-1; else{ t2.m=t2.m+60-1; t2.h-=1; } } if(t2.m>t1.m) { t3.m=t2.m-t1.m; } else { t3.m=t2.m+60-t1.m; if(t2.h>0) t2.h=t2.h-1; } if(t2.h>=t1.h) { t3.h=t2.h-t1.h; } printf("%d:%02d:%02d",t3.h,t3.m,t3.s); } |
Double click to view unformatted code.