L1-018. 大笨钟
问题描述
问题分析
会发现输入是字符串形式,而具体判断时间的操作又是对数字的判断,所以要将字符串形式的数字转换为整形的数字,再根据题目要求求解,剩下的就好做了。
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
cin >> str;
int h = (str[0] - '0') * 10 + (str[1] - '0');
int m = (str[3] - '0') * 10 + (str[4] - '0');
if (h < 12 || h == 12 && m == 0) {
cout << "Only " << str << ". Too early to Dang.";
return 0;
}
int count = h - 12;
if (m > 0)
count++;
for (int i = 0; i < count; i++) {
cout << "Dang";
}
return 0;
}