HDU - 2033 人见人爱A+B

题目链接:

点击打开链接


/*
  贴这题的目的是为了提醒自己,技无止境,诚惶诚恐
  
  本来以为自己学完了C++以后,用结构体来写,这代码应该够简洁清晰了,结果顺手一搜题解,发现别人的写法更简单...
  
  见:http://blog.csdn.net/erick_who/article/details/43908257
  
  是我陷入思维定势,把事情想复杂了啊! T^T
*/



//自己初次
#include <iostream>
using namespace std;
struct time
{
	int h, m, s;
	time(int h1 = 0, int m1 = 0, int s1 = 0) : h(h1), m(m1), s(s1)
	{
	}
	void init()
	{
		cin >> h >> m >> s;
	}
	time add(const time& t)
	{
		time c(h + t.h, m + t.m, s + t.s);
		if (c.s >= 60)
		{
			c.m += c.s / 60;
			c.s %= 60;
		}
		if (c.m >= 60)
		{
			c.h += c.m / 60;
			c.m %= 60;
		}
		return c;
	}
	void display()
	{
		cout << h << " " << m << " " << s << endl;
	}
};
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		time a, b;
		a.init();
		b.init();
		time c = a.add(b);
		c.display();
	}
	return 0;
}

//看完题解后,重写一次
#include <iostream>
using namespace std;
int main()
{
	int n, AH, AM, AS, BH, BM, BS;
	cin >> n;
	while (n--)
	{
		cin >> AH >> AM >> AS >> BH >> BM >> BS;
		AS += BS;
		AM += (AS / 60) + BM;
		AH += (AM / 60) + BH;
		cout << AH << " " << (AM % 60) << " " << (AS % 60) << endl; 
	}
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值