20分求助

B3720 [语言月赛202303] Out for Dinner B

lyx703 @ 2024-01-30 16:03:48

代码如下

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long p;
    string c;
    cin>>p>>c;
    if(c=="AA")
    {
        cout<<p;
    }
    if(c=="AB"||c=="BA")
    {
        cout<<p*0.8;
    }
    if(c=="AC"||c=="CA")
    {
        cout<<p*0.7;
    }
    if(c=="BC"||c=="CB")
    {
        cout<<p*0.6;
    }
    if(c=="BB")
    {
        cout<<p*0.8;
    }
    if(c=="CC")
    {
        cout<<p*0.7;
    }
 } 

by __O_v_O__ @ 2024-01-30 17:27:38

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long p;
    string c;
    cin>>p>>c;
    if(c=="AA")
    {
        cout<<p;
    }
    if(c=="AB"||c=="BA")
    {
        cout<<p*8/10;
    }
    if(c=="AC"||c=="CA")
    {
        cout<<p*7/10;
    }
    if(c=="BC"||c=="CB")
    {
        cout<<p*6/10;
    }
    if(c=="BB")
    {
        cout<<p*8/10;
    }
    if(c=="CC")
    {
        cout<<p*7/10;
    }
 } 

by __O_v_O__ @ 2024-01-30 17:28:57

@lyx703 精度问题吧,先乘10再除就行了


by lyx703 @ 2024-01-31 13:39:31

@sheryang_CE 谢谢


|