zhuweiqi @ 2023-03-13 18:53:08
by Mr_Biantainne @ 2023-03-13 18:58:19
可能是浮点数精度误差?
by Ishr_Mla @ 2023-03-13 19:21:58
如果某些测试点数据里的x不是整十数,那么AC代码不可能通过。换句话说,如果消费价格是85元,买了两份B餐,打8折的结果应该是68元而非64元。
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long x;
char a, b;
cin>>x>>a>>b;
if (a > b)
swap(a,b);
if (a=='B' && b=='C')
x = x * 6 / 10;
else if (a=='B')
x = x * 8 / 10;
else if (a=='C')
x = x * 7 / 10;
cout<<x;
return 0;
}
另外二楼说的对。
证据:
#include<bits/stdc++.h>
using namespace std;
int main()
{
double x;
char a, b;
cin>>x>>a>>b;
if (a > b)
swap(a,b);
if (a=='B' && b=='C')
x = x / 10 * 6;
else if (a=='B' || b == 'B')
x = x / 10 * 8;
else if (a=='C' || b == 'C')
x = x / 10 * 7;
cout<<(long long)x;
return 0;
}
同样是50分。
by Ishr_Mla @ 2023-03-13 19:29:16
AC代码贴错了,躺。
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long x;
char a, b;
cin>>x>>a>>b;
if (a > b)
swap(a,b);
if (a=='B' && b=='C')
x = x * 6 / 10;
else if (a=='B' || b=='B')
x = x * 8 / 10;
else if (a=='C' || b=='C')
x = x * 7 / 10;
cout<<x;
return 0;
}
by WYXkk @ 2023-03-13 19:38:05
@zhuweiqi 双精度浮点数可能有一个大概在 (long long)(999999999999999990ll*0.6)
。
by zhuweiqi @ 2023-03-13 19:42:20
@WYXkk 原来如此,还真是浮点数误差,我明白了
by Pink_Cut_Tree @ 2023-04-10 21:59:50
WYXkk楼下的楼下
by CSP_AK_xyy20110721 @ 2023-06-12 22:03:12
WYYkk的楼下的楼下的楼下