HDU

来源:互联网 发布:阿里云空间购买流程 编辑:程序博客网 时间:2024/05/23 02:04

题目链接:

点击打开链接


/*  贴这题的目的是为了提醒自己,技无止境,诚惶诚恐    本来以为自己学完了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;}