输入两个时间,包括时分秒,比较计算并输出其中较大的那个时间。 输出格式提醒:输出格式为24小时以内的时:分:秒,例如12:12:12c++
时间: 2023-06-27 18:03:07 浏览: 42
以下是C++代码实现:
```cpp
#include <iostream>
using namespace std;
int main() {
int h1, m1, s1, h2, m2, s2;
char c;
cin >> h1 >> c >> m1 >> c >> s1 >> h2 >> c >> m2 >> c >> s2;
int total_seconds1 = h1 * 3600 + m1 * 60 + s1;
int total_seconds2 = h2 * 3600 + m2 * 60 + s2;
if (total_seconds1 >= total_seconds2) {
printf("%02d:%02d:%02d\n", h1, m1, s1);
} else {
printf("%02d:%02d:%02d\n", h2, m2, s2);
}
return 0;
}
```
输入格式为:h1:m1:s1 h2:m2:s2,其中 h1,m1,s1,h2,m2,s2 都是整数。程序将两个时间转换成总秒数,然后比较大小,输出较大的那个时间。输出格式为 24 小时制的时:分:秒,其中时、分、秒都有两位,不足两位前面补零。