时钟类
来源:互联网 发布:接口 java 编辑:程序博客网 时间:2024/05/18 00:29
1.题目:
Problem Description
定义一个时钟类(Clock),含三个整形元素(H,M,S)分别代表小时,分钟,秒,构造初始化数据函数,另外,定义一个函数实现两个时钟相加,一个显示函数,输出格式为H:M:S
Input
输入数据有多组,每组两行,第一行输入三个整数:h1(0<=h1<=23),m1(0<=m1<=59),s1(0<=s1<=59),分别代表是一个24小时制的电子钟开始时显示的小时,分钟,秒,第二行仍输入三个整数:h2(h2>=0),m2(0<=m2<=59),s1(0<=s2<=59),代表电子钟经历的时长
Output
每组输出占一行,输出现在电子钟上显示的时间,格式为“小时:分钟:秒”,注意:此题不考虑电子钟显示00~09的形式,用0~9表示即可。
Sample Input
13 30 301 10 301 0 025 0 0
Sample Output
14:41:02:0:0
2.参考代码:
#include <iostream>using namespace std;class CLOCK{ private: int hour, minute, second; public: CLOCK(int h = 0, int m = 0, int s = 0); CLOCK operator+(CLOCK&); void show(); };CLOCK::CLOCK(int h, int m, int s){ hour = h; minute = m; second = s;}CLOCK CLOCK::operator+(CLOCK& c){ CLOCK x; x.hour = hour + c.hour; x.minute = minute + c.minute; x.second = second + c.second; if (x.second / 60) x.minute++; if (x.minute / 60) x.hour++; x.second %= 60; x.minute %= 60; x.hour %= 24; return x;}void CLOCK::show(){ cout << hour << ":" << minute << ":" << second << endl;}int main(){ int h1, m1, s1, h2, m2, s2; while (cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2) { CLOCK x(h1, m1, s1), y(h2, m2, s2), z; z = x + y; z.show(); } return 0;}
3.感想:
就是这题,坑爹死了,卡了我好久,刚开始没有想到要用求模的,因为题目的数据范围,恶心死了,动买叼!
在此做个纪念。
- 时钟类
- 时钟类
- 时钟类
- 时钟类
- 时钟类练手
- C++的时钟类
- ClockView时钟类
- c++基础:时钟类
- 视频中的 时钟类
- 时钟
- 时钟
- 时钟
- 时钟
- 时钟
- 时钟
- 时钟
- 时钟
- 时钟
- 用Orachard与Bootstrap建站
- 数据库分表处理设计思想和实现
- Oracle的锁表与解锁
- C#中读取带有Xmlns命名空间的XML文件
- 黑马训练营 ----------- DataStream与对象的序列化
- 时钟类
- 使用WakeLock使Android应用程序保持后台唤醒 .
- 男人应该怎样对待爱情?
- 【安装与配置】--Nginx
- IREPORT crossdata PDF 不显示中文
- Android自定义控件之广告视图
- NSSet使用介绍
- 九度笔记之 二叉树遍历
- 最近用plsql通过 @sql语句路径的方式 因为手贱导致sql文件执行不下去的问题