C language Time Summary

Title Description

Competition in the rankings, is generally ranked according to the number of questions to do, but as the same number of questions, each question press to do the total time spent on rank.
The following summary of programming time.

Entry

A first input n (1 <= n <= 10), n represents the total made problem.
Then make the n input time spent in each title, the format HH: MM: SS, wherein, when (00 <= HH <10) HH represents, MM is minutes (00 <= MM <= 59 ), SS represents second (00 <= SS <= 59 ).

Export

The total time the output after n time summary, the format HH: MM: SS. After the summary, 00 <= HH <100

Sample input Copy

2
01:08:25
02:12:45

Sample output Copy

03:21:10

Code

#include<stdio.h>
#include<math.h>
int main()
{
	int n,h=0,m=0,s=0,a,b,c;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d:%d:%d",&a,&b,&c);
		h=h+a;
		m=m+b;
		s=s+c;
	}
	m=m+s/60;
	s=s%60;
	h=h+m/60;
	m=m%60;
	printf("%02d:%02d:%02d",h,m,s);//注意时间格式
	return 0;
}
Published 47 original articles · won praise 29 · views 1474

Guess you like

Origin blog.csdn.net/Qianzshuo/article/details/103886729