您的位置:首页 > 编程语言

HDU - 2033 人见人爱A+B

2017-11-10 21:53 225 查看
题目链接:

点击打开链接

/*
贴这题的目的是为了提醒自己,技无止境,诚惶诚恐

本来以为自己学完了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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM 编程 HDU