[Los] Valley Xinshoucun simple string p1055 ISBN number

p1055 ISBN number [portal]

What's algorithm tags:

Thinking: Read a string directly into the string of numbers, then the string loop for processing into a digital string stored in the array (if X, is stored 10); and then determining whether the request is the correct code book, and if so, output "right", otherwise the output of the top ten before the first code book, and finally output a correct identification code.

#include<bits/stdc++.h>

using namespace std;

char a1[15];
int a[15],num,sum;

int main(){
    scanf("%s",a1);
    for(int i=0;i<13;i++){
        if(a1[i]=='X'){
            a[++num]=10;
        }
        if(a1[i]!='-'&&a1[i]!='X')
        a[++num]=a1[i]-'0';
    }
    for(int i=1;i<=9;i++){
        a[i]*=i;
        sum+=a[i];
    }
    sum%=11;
    if(sum==a[10])
    cout<<"Right"<<endl;
    else {
        for(int i=0;i<12;i++)
        cout<<a1[i];
        if(sum==10)cout<<"X";
        else cout<<sum;
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/zhuier-xquan/p/10958352.html