L1-018 大笨钟 (10 分)

微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。不过由于笨钟自己作息也不是很规律,所以敲钟并不定时。一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那个整点数;如果过了整点,就敲下一个整点数。另外,虽然一天有24小时,钟却是只在后半天敲1~12下。例如在23:00敲钟,就是“当当当当当当当当当当当”,而到了23:01就会是“当当当当当当当当当当当当”。在午夜00:00到中午12:00期间(端点时间包括在内),笨钟是不敲的。

下面就请你写个程序,根据当前时间替大笨钟敲钟。

输入格式:
输入第一行按照hh:mm的格式给出当前时间。其中hh是小时,在00到23之间;mm是分钟,在00到59之间。

输出格式:
根据当前时间替大笨钟敲钟,即在一行中输出相应数量个Dang。如果不是敲钟期,则输出:

Only hh:mm. Too early to Dang.
其中hh:mm是输入的时间。

输入样例1:
19:05
输出样例1:
DangDangDangDangDangDangDangDang
输入样例2:
07:05
输出样例2:
Only 07:05. Too early to Dang.

注意输出格式

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#define ll long long
using namespace std;

int main() {
	string ss;
	while (cin >> ss) {
		ll x;
		x = (ss[0] - '0') * 10 + (ss[1] - '0');
		ll y;
		y = (ss[3] - '0') * 10 + (ss[4] - '0');
		if ((x < 12) || (x == 12 && y == 0) || x >= 24) {
			cout<<"Only " << ss[0] << ss[1] << ss[2] << ss[3] << ss[4]<<".  Too early to Dang." << endl;
		}
		else {
			ll count = x - 12;//判断个数
			for (ll i = 0; i < count; i++) {
				cout << "Dang";
			}
			if (y != 0) {
				cout << "Dang" << endl;
			}
			else {
				cout << endl;
			}
		}
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_44231195/article/details/89366009