题解 | 牛牛的时钟

#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;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务