View Code of Problem 56

#include<stdio.h>
#include<math.h>
//二刷 注意一下输出格式就好了,本题不难。 
int main(){
	int h1, m1, s1, h2, m2, s2;
	while(scanf("%d:%d:%d", &h1, &m1, &s1) != EOF) {
		scanf("%d:%d:%d", &h2, &m2, &s2);
		int sum1 = h1*3600 + m1*60 + s1;
		int sum2 = h2*3600 + m2*60 + s2;
		int differ = abs(sum1-sum2); //因为本题并没有说时间点1肯定先于时间点2,所以取绝对值 
		int newh = differ/3600;
		int newm = differ%3600/60;
		int news = differ%3600%60;
		printf("%d:%02d:%02d\n", newh, newm, news); //看清格式,h不需要前补0,也不要求位宽 
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 56