Why is it wrong? Please persuade me.

P1055 [NOIP2008 普及组] ISBN 号码

_0_1_ @ 2022-08-02 16:34:39

#include<bits/stdc++.h>
using namespace std;
char c[15];
int fl;
int t(char a){
    return a-'0';
}
int main(){
    cin>>c;
    int j=0;
    for(int i=0;i<=10;i++){
        if(i!=(1||5)){

        //There is the wrong,which should be modified to "i!=1&&i!=5"

            fl+=(++j)*t(c[i]);
        } 
    }
    fl%=11;
    if(fl==10) fl='X'-'0';
    if(c[12]=='0'+fl) cout<<"Right";
    else{
        c[12]='0'+fl;
        cout<<c;
    }
    return 0;
}

by int__128 @ 2022-08-02 16:40:12

@00000110hh

Are you English?

Please speak in Chinese.


by ajahjahah @ 2022-08-02 16:42:41

Oh, you is english men!

i!=(1||5)能跟i!=1||i!=5一样吗

(1||5)->true

i!=(1||5)->i!=true

但是只要i\neq 0这个就不成立

There is the wrong

英语不好就别来装13行吗大哥


by SegTree @ 2022-08-02 16:46:29

@00000110hh

Why is it wrong?

There is the wrong

is you a english man?


by _0_1_ @ 2022-08-02 16:54:15

@int__128 为了引起大佬注意,专门的


by irris @ 2022-08-02 16:55:12

Didn't been tricking by these gay!

Maybe theese was an small accccccccount!!!


by _0_1_ @ 2022-08-02 17:08:15

@ajahjahah 谢谢大佬;

There is the wrong

有什么毛病吗?


by NaOH_Frog @ 2022-08-02 17:32:12

sir you is inglish men sir orz bro sir


by ajahjahah @ 2022-08-02 18:39:28

众所周知,wrong是名词(doge)


by asdypeij @ 2022-08-03 09:17:47

In your code, (1||5) will return true(bool type), your i is an integer.

When a bool type value is compared with an integer, true will be converted to 1.

So long as i is not equal to 1, the if statement will be run.

#include<bits/stdc++.h>
using namespace std;
char c[15];
int fl;
int t(char a){
    return a-'0';
}
int main(){
    cin>>c;
    int j=0;
    for(int i=0;i<=10;i++){
        /*
        In your code, (1||5) will return true(bool type), your i is an integer.
        When a bool type value is compared with an integer, true will be converted to 1.
        So long as i is not equal to 1, the if statement will be run. 
        */
        if(i!=(1||5)){      
            printf("i=%d\n", i);
            fl+=(++j)*t(c[i]);
        } 
    }
    fl%=11;
    if(fl==10) fl='X'-'0';
    if(c[12]=='0'+fl) cout<<"Right";
    else{
        c[12]='0'+fl;
        cout<<c;
    }
    return 0;
}

by asdypeij @ 2022-08-03 09:30:13

In mathematics !(a||b) means !a&&!b, but in code, it's not!


| 下一页