#include<stdio.h> void swap(int *a,int *b){ int temp; temp = *a; *a = *b; *b = temp; } int main(){ int h1,m1,s1,h2,m2,s2,h3,m3,s3; int dif; //printf("请输入出发时间:"); scanf("%d:%d:%d",&h1,&m1,&s1); //printf("输入到达时间:"); scanf("%d:%d:%d",&h2,&m2,&s2); if(h1>h2){ swap(&h1,&h2); swap(&m1,&m2); swap(&s1,&s2); } dif = (((h2-h1)*60+m2)*60+s2)-(m1*60+s1); //秒钟差 h3 = (int)dif/3600; m3 = (dif%3600)/60; s3 = (dif%3600)%60; printf("%d:%d:%d\n",h3,m3,s3); } |
Double click to view unformatted code.