50分 求助神犇

P1055 [NOIP2008 普及组] ISBN 号码

OIer_fish @ 2024-02-21 10:00:10


```
#include<bits/stdc++.h>
using namespace std;
int main(){
    char str[20];
    int cnt=0,ans=0;
    scanf("%s",str+1);
    int len=strlen(str+1);
    for(int i=1;i<=len-1;i++){
        if(str[i]=='-'){
            continue;
        }
        int now=str[i]-'0';
        cnt=cnt+1;
        ans+=now*cnt;
    }
    ans=ans%11;
    if(ans=10){
        if(str[len]=='X'){
            cout<<"Right"<<endl;
        }
        else{
            str[len]='X';
            printf("%s\n",str+1);
        }
    }
    else{
        if(str[len]=='0'+ans){
            cout<<"Right"<<endl; 
        }
        else{
            str[len]='0'+ans;
            printf("%s\n",str+1);
        }
    }
    return 0;

}
```

by Loyal_Soldier @ 2024-02-21 10:16:17

@YZHcsp AC代码:

#include<bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,b1,b2,b3,c1,c2,c3,c4,c5,y;
char s;
scanf("%d-%d-%d-%c",&a,&b,&c,&s);
b1=b/100;
b2=b/10%10;
b3=b%10;
c1=c/10000;
c2=c/1000%10;
c3=c/100%10;
c4=c/10%10;
c5=c%10;
y=(a*1+b1*2+b2*3+b3*4+c1*5+c2*6+c3*7+c4*8+c5*9)%11;
if(s=='X'){
    if(y==10){
        cout<<"Right";
    }
    else{
        printf("%d-%d-%d-%d",a,b,c,y);
    }
}
else{
    s=s-48;
    if(y==10){
        printf("%d-%d-%d-X",a,b,c);
    }
    else if(y==s){
        cout<<"Right";
    }
    else{
        printf("%d-%d-%d-%d",a,b,c,y);
    }
}
    return 0;
}

by Loyal_Soldier @ 2024-02-21 10:17:45

一个很简单的题,不用数组就行


by OIer_fish @ 2024-02-21 10:23:51

@huangkaikai ...... 好吧 栓q


by xzy_caiji @ 2024-02-21 10:27:33

@YZHcsp 不要听楼上的!您的几乎是对的!只要把第17行的=改成==就行了!


by xzy_caiji @ 2024-02-21 10:28:23

就是把ans=10改成ans==10


by OIer_fish @ 2024-02-21 10:29:01

@xzy_caiji 为啥嘞 蒟蒻不理解


by xzy_caiji @ 2024-02-21 10:30:31

ans=10就是把ans赋值为10并返回10,而ans==10是判断ans是否等于10


by xzy_caiji @ 2024-02-21 10:32:03

if(ans=10){
    ……
}

程序会一直进入这个分支,不管ans等不等于10


by xzy_caiji @ 2024-02-21 10:32:15

@YZHcsp


by xiangzhenze611 @ 2024-02-21 10:33:02

@YZHcsp 楼上说的没错,要判断两个值是否相等要用 ==


| 下一页