山东理工OJ 1177C语言实验——时间间隔

来源:互联网 发布:淘宝hd下载 编辑:程序博客网 时间:2024/04/28 19:42

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1177

题目描述

从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。

输入

输入包括两行。
第一行为时间点1。
第二行为时间点2。

输出

以“小时:分钟:秒”的格式输出时间间隔。
格式参看输入输出。

示例输入

12:01:1213:09:43

示例输出

01:08:31

#include <stdio.h>#include <stdlib.h>#include <math.h>int timetoseconds(int h,int m,int s){return (h*60+m)*60+s;}void secondstotime(int t,int *h,int *m,int *s){*s=t%60; t/=60;*m=t%60; t/=60;*h=t%60; t/=60;}int main(){    int h1,m1,s1,h2,m2,s2;    int t1,t2,dt;    int dh,dm,ds;    scanf("%02d:%02d:%02d",&h1,&m1,&s1);scanf("%02d:%02d:%02d",&h2,&m2,&s2);t1=timetoseconds(h1,m1,s1);t2=timetoseconds(h2,m2,s2);dt=labs(t1-t2);secondstotime(dt,&dh,&dm,&ds);printf("%02d:%02d:%02d\n",dh,dm,ds);return 0;} /**************************************Problem id: SDUT OJ 1177 User name: 2333 Result: Accepted Take Memory: 280K Take Time: 0MS Submit Time: 2016-07-10 16:06:04  **************************************/


0 0
原创粉丝点击