团体程序设计天梯赛-练习集 L1-018 大笨钟 (10分)
程序员文章站
2024-02-27 00:02:58
...
#include <iostream>
using namespace std;
int main()
{
int a, b, num;
scanf("%d:%d", &a, &b);
if (a < 12 || (a == 12 && b == 0))
{
printf("Only %02d:%02d. Too early to Dang.", a, b);
}
else
{
num = a - 12;
if (b > 0)
{
num++;
}
for (int i = 0; i < num; i++)
{
printf("Dang");
}
printf("\n");
}
return 0;
}
简化之后:
#include <iostream>
using namespace std;
int main()
{
int hour, min;
scanf("%d:%d", &hour, &min);
if (hour <= 12)
{
printf("Only %02d:%02d. Too early to Dang.", hour, min);
}
else
{
hour -= 12;
for (int i = 0; i < hour; i++)
{
cout << "Dang";
}
if (min > 0)
{
cout << "Dang";
}
}
return 0;
}