对于铸币(指我)非常不友好的题目,心态容易写炸。
观察数据范围,显然需要读入字符串类型
题目
样例及hack:
样例
1 4
Happy birthday to YXGG
hack1
0 500
Happy birthday to YXGG //0.5直接把小数抹掉,变成0.0,赚了
hack2
101101 50
Happy birthday to MFGG // 抹掉小数,整数进1,亏了
hack3
200202211 00000
PLMM // 把小数抹掉,相当于没抹掉
hack4
101 0500
Happy birthday to YXGG
hack5
808 5000005
Happy birthday to MFGG
hack6
1234213123131231312312 123234512312313
Happy birthday to YXGG
思路:
从结果出发
什么时候会平手?当且仅当字符串B等价0,输出"PLMM"
什么时候价格会变便宜?当且仅当小数部分在意义上小于0.5 或者 在意义上等于0.5且整数部分为偶数,输出"YXGG"
否则价格会变贵,输出“MFGG”
因为字符串,所以需要手写判断,直接贴上最终代码
心平气和的代码
#include <iostream>
#include <cstring>
using namespace std;
const int N = 1e5 + 12;
bool is_zero(string s)
{ // s 是否等价于0
for (auto &u:s) // 只要不是0就退出
if (u != '0') return 0;
return 1;
}
bool is_equal_5(string s)
{ // s 是否等价于 5
if (s[0] != '5') return 0; // 第一位是5
for (int i=1;i < s.size();i ++ )
if (s[i] != '0') return 0;// 后面都是0
return 1;
}
bool is_even(string a)
{ // a 是否是偶数
int x = a[a.size()-1] - '0';
return !(x%2); // 判断最后一位
}
signed main()
{
string a, b; cin >> a >> b;
if (is_zero(b))
puts("PLMM");
else if (is_even(a) && is_equal_5(b) || b[0] < '5')
puts("Happy birthday to YXGG");
else puts("Happy birthday to MFGG");
return 0;
}