0分,全WA,本地里测试,一直输出0

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

LINYUHENG @ 2024-05-31 19:31:31


#include <bits/stdc++.h>
using namespace std;
long long x,y;
char a,b;

int main(){
    cin>>x>>a>>b;
    if(b<a) swap(a,b);
    if(a=='B'&&b!='C') y=8;
    else if(a!='B'&&b=='C') y=7;
    else if(a=='B'&&b=='C') y=6;
    x*=y/10;
    cout<<x;
    return -0;
}
debug者有赏

by MrFudgeMonkey @ 2024-05-31 19:52:11

整数的y小于10,那么y/10=0,x也就变成0了

建议你把一些变量改成double类型


by Bitwise_Operation @ 2024-05-31 19:54:51

@LINYUHENG 题目最下面:可能a、b会相同(点1)


by Bitwise_Operation @ 2024-05-31 19:55:15

@LINYUHENG return -0(点2)


by Bitwise_Operation @ 2024-05-31 19:56:20

@LINYUHENG 没判断a、b不等于b菜、c菜的情况(点3)


by Bitwise_Operation @ 2024-05-31 20:04:45

@LINYUHENG 还要各判断一下,即a=='B'&&b!='C'要写成(a=='B'&&b!='C')||(a!='C'&&b=='B'),因为可能有个变量是'A',这样就不好判断


by flylight000 @ 2024-05-31 20:16:41

参考代码

#include <bits/stdc++.h>
using namespace std;
#define int long long
/*快读*/
void read(int &p){
    p = 0;
    int k = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-'){
            k = -1;
        }
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        p = p * 10 + c - '0';
        c = getchar();
    }
    p *= k;
    return ;
}
/*快输*/
void writee(int x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
        writee(x / 10);
    }
    putchar(x % 10 + '0');
}

bool a,b,c;
int n;

signed main(){
    read(n);//读取金额
    char ch = getchar();
    while(ch == 'A' || ch == 'B' || ch == 'C'){
        if(ch=='A'){
            a = true;
        }
        if(ch=='B'){
            b = true;
        }
        if(ch=='C'){
            c = true;
        }
        ch = getchar();
    }//读取当前字符并赋值

    if(b && !c){
        writee(n * 8 / 10);
    }
    else if(c && !b){
        writee(n * 7 / 10);
    }
    else if(c && b){
        writee(n * 6 / 10);
    }
    else{
        writee(n);
    }
    return 0;
}

by LINYUHENG @ 2024-06-01 12:24:46

@flylight000 快读快输感觉可以用scanf()and printf()


|