题解 | 牛牛的时钟

#include <stdio.h>

struct clock
{
	int hour;
	int min;
	int sec;
};

int main()
{
	int n = 0;
	scanf("%d", &n);
	int i = 0;
	int sec[100] = { 0 };
	for (i = 0; i < n; i++)
	{
		scanf("%d", &sec[i]);
	}
	struct clock t = { 0, 0, 0 };
	struct clock p = { 0, 0, 0 };
	for (i = 0; i < n; i++)
	{
		p.sec += sec[i];
		if (p.sec < 60)
		{
			t.hour = 0;
			t.min = 0;
			t.sec = p.sec;
    	}
		else if (p.sec >= 60 && p.sec < 3600)
		{
			t.hour = 0;
			t.min = (p.sec) / 60;
			t.sec = (p.sec) - (t.min) * 60;
		}
		else
		{
			t.hour = (p.sec) / 3600;
			t.min = ((p.sec) - (t.hour) * 3600) / 60;
			t.sec = (p.sec) - (t.hour) * 3600 - (t.min) * 60;
		}
		printf("%d %d %d\n", t.hour, t.min, t.sec);
	}
	return 0;
}

全部评论

相关推荐

争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-01 11:47
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务