题解

272 条题解

  • 7
    @ 2017-10-28 15:56:26

    var

    ans:integer;
    s:string;
    ch:char;
    begin
    ans:=0;
    read(s);
    ans:=ans+(ord(s[1])-48)*1+(ord(s[3])-48)*2+(ord(s[4])-48)*3+(ord(s[5])-48)*4;
    ans:=ans+(ord(s[7])-48)*5+(ord(s[8])-48)*6+(ord(s[9])-48)*7+(ord(s[10])-48)*8;
    ans:=ans+(ord(s[11])-48)*9;

    ans:=ans mod 11;
    if ans=10 then ch:='X' else ch:=chr(ans+48);
    if ch=s[13] then write('Right')
    else begin write(copy(s,1,12)); writeln(ch);end;
    end.

  • 3
    @ 2017-10-01 15:23:26

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int a[2],b[4],c[6];
    int main()
    {
    //freopen("ISBN.in","r",stdin);
    //freopen("ISBN.out","w",stdout);
    int r;
    string n;
    cin>>n;
    r=((n[0]-48)*1+(n[2]-48)*2+(n[3]-48)*3+(n[4]-48)*4+(n[6]-48)*5+(n[7]-48)*6+(n[8]-48)*7+(n[9]-48)*8+(n[10]-48)*9)%11;
    if(r==10&&n[12]=='X')
    cout<<"Right"<<endl;
    if(r+48==n[12])
    cout<<"Right"<<endl;
    else if(r!=10&&n[12]!=r)
    {
    for(int i=0;i<12;i++)
    cout<<n[i];
    cout<<r;
    }
    else if(r==10&&n[12]!='X')
    {
    for(int i=0;i<12;i++)
    cout<<n[i];
    cout<<"X";
    }
    return 0;
    }

  • 2
    @ 2020-02-02 19:54:38

    挺简单的,就不多说了,上代码

    #include<iostream>
    using namespace std;
    char icode;
    bool jug(const char* a) {
        int j = 1, sum = 0;
        for (int i = 0; i < 11; i++)
        {
            if (i != 1 && i != 5) {
                sum += (a[i] - 48) * j;
                j++;
            }
        }
        if (sum % 11 != 10)icode = sum % 11 + 48;
        else icode = 'X';
        if (icode == a[12])return true;
        else return false;
    }
    int main()
    {
        char Yisbn[13];
        cin >> Yisbn;
        if (jug(Yisbn))cout << "Right";
        else {
            Yisbn[12] = icode;
            cout << Yisbn;
        }
        return 0;
    }
    
  • 1
    @ 2019-05-26 17:45:13
    #include<stdio.h>
    int main()
    {
        char a[13];
        int i,k=1,sum=0,j,f=0;
        for(i=0;i<=12;i++)
        {
            scanf("%c",&a[i]);
            if(a[i]!='-' && i!=12) //避开‘- ’与最后一位判断的输入; 
                {sum=sum+(a[i]-'0')*k;k++;}//进行k的自增a[i]为字符型所以 减去‘0’ 
        }
        j=sum%11;
        if(a[12]=='X' && j==10){printf("Right");f=1;}//用于判断输入为X 
        if(j==a[12]-'0')
           printf("Right");
        else if(f!=1)
            {
                if(j+'0'!='10')a[12]=j+'0';
                if(j+'0'==':')a[12]='X';          //各位大牛注意了48+10=58也就是‘:’ 
                for(i=0;i<=12;i++)
                {if(a[i]==':'){printf("X");i++;}///各48+10=58也就是‘:’ (重复判断)
                printf("%c",a[i]);}
            }
        return 0;
    }
    
  • 1
    @ 2019-02-13 20:12:07

    C++

    #include<iostream>
    using namespace std;
    char s[100];
    int main()
    {
    int m=0,y=0;
    for(int i=1;i<=13;i++)
    cin>>s[i];
    for(int i=1;i<=12;i++)
    {
    if(s[i]!='-')
    {
    y++;
    m+=(s[i]-48)*y;
    }
    }
    int x=m%11;
    int w=s[13]-48;
    if(((x==10)&&(s[13]=='X'))||(w==x))
    cout<<"Right"<<endl;
    else
    for(int i=1;i<=13;i++)
    {
    if((i==13)&&(x==10)) cout<<"X";
    else if((i==13)&&(x!=10)) cout<<(char)(x+48);
    else cout<<s[i];
    }
    }

  • 1
    @ 2018-09-04 17:54:02
    s=input()
    list=s.split('-')
    s=''
    for i in list:
        s=s+i
    count=0
    for i in range(9):
        count+=int(s[i])*(i+1)
    a=str(count%11)
    if(int(a)==10):
        a='X'
    if(a==s[9]):
        print('Right')
    else:
        print(s[0] + '-' + s[1:4] + '-' + s[4:9] + '-' + a)
    
    '''
    
  • 1
    @ 2017-11-09 20:16:00
    //
    // Created by eh5 on 17-11-9.
    //
    
    
    #include <stdio.h>
    
    
    int main() {
        char isbn[13];
        scanf("%s", isbn);
        int code = 0;
        char code_s = '\0';
        for (int i = 0, cnt = 0; i < 11; i++) {
            if (isbn[i] == '-') continue;
            code += (isbn[i] - '0') * (++cnt);
        }
        code %= 11;
        if (code == 10) code_s = 'X';
        else code_s = '0' + code;
        if (isbn[12] == code_s) printf("Right\n");
        else {
            isbn[12] = code_s;
            printf("%s\n", isbn);
        }
    
    }
    

    送分题

  • 1
    @ 2017-03-22 21:41:12

    var s1,s:ansistring;
    i,t,c,co,h:longint;
    begin
    readln(s);
    t:=0;
    h:=0;
    for i:=1 to length(s)-1 do
    begin
    if (s[i]>='0') and (s[i]<='9') then
    begin
    h:=h+1;
    val(s[i],c,co);
    t:=t+c*h;
    end;
    end;
    t:=t mod 11;
    if chr(t+48)=s[length(s)] then write('Right')
    else if (t=10) and (s[length(s)]='X') then write('Right')
    else begin for i:=1 to length(s)-1 do write(s[i]); if t=10 then write('X') else write(t); end;
    end.

  • 0
    @ 2020-05-22 20:59:32
    #include <bits/stdc++.h>
    using namespace std;
    int e[18],icb;
    int main()
    {
        //ISBN号码(NOIP)
        char icp,ic;
        int i;
        scanf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-%c",&e[1],&e[2],&e[3],&e[4],&e[5],&e[6],&e[7],&e[8],&e[9],&ic);
        for(i=1;i<=9;i++) icb+=e[i]*i;
        switch(icb%11)
        {
            case 1: icp='1';break;
            case 2: icp='2';break;
            case 3: icp='3';break;
            case 4: icp='4';break;
            case 5: icp='5';break;
            case 6: icp='6';break;
            case 7: icp='7';break;
            case 8: icp='8';break;
            case 9: icp='9';break;
            default: icp='X';
        }
        if (ic==icp) printf("Right");
        else printf("%d-%d%d%d-%d%d%d%d%d-%c",e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],icp);
    }
    
  • 0
    @ 2020-04-11 22:43:28
    #include <iostream>         //[2008普及组-A]ISBN号码
    #include <algorithm>
    using namespace std;
    
    int atoi(char a)
    {
        return a - '0';
    }
    
    char judge(string str)
    {
        string sam = "0123456789X";
        int k = 1;
        int s = 0;
        for (int i = 0; i < str.length() - 1; i++)
            if(str[i] >= '0' && str[i] <= '9')
                s += atoi(str[i]) * k++;
    
        return sam[s % 11];
    }
    
    int main()
    {
        string str;
        cin >> str;
        char end = judge(str);
        if(end == *(str.end() - 1))
            str = "Right";
        else
            *(str.end() - 1) = end;
    
        cout << str << endl;
    
        return 0;
    }
    
    
  • 0
    @ 2020-03-11 15:47:49

    这道题是出来考字符串处理的,但用格式化输入的方法也能过

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int _1, _2, _3, _4, _5, _6, _7, _8, _9, isbn, risbn;
        char _10;
        scanf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-%c", \
            &_1, &_2, &_3, &_4, &_5, &_6, &_7, &_8, &_9, &_10);
        isbn = _10 == 'X' ? 10 : _10 - 48;
        risbn = (_1 + _2 * 2 + _3 * 3 + _4 * 4 + 5 * _5 \
            + 6 * _6 + 7 * _7 + 8 * _8 + 9 * _9) % 11;
        _10 = risbn == 10 ? 'X' : risbn + 48;
        if (isbn == risbn)printf("Right");
        else printf("%d-%d%d%d-%d%d%d%d%d-%c", \
            _1, _2, _3, _4, _5, _6, _7, _8, _9, _10);
    }
    
  • 0
    @ 2019-10-03 09:53:29

    像我这种憨批,都不用字符串做的
    代码如下

    #include<iostream>
    using namespace std;
    int main()
    {
        int a,b,c,k=0,p,h,x=100,z=10000;
        char e,f,g,d;
        cin>>a>>e>>b>>f>>c>>g>>d;
        int j=a,l=b,m=c;
        if(d>='0'&&d<='9')
        {
            h=int(d)-48;
        }
        else
        {
            h=10;
        }
        
        k+=a;
        
        int i=2; 
        for(int q=1;q<=3;q++)
        { 
            if(b<10)
            {
                k+=b*i;
                i++;
                break;
            }
            else
            {
                p=b/x;
                b-=p*x;
                k+=p*i;
                x/=10;
                i++;
            }
        }
        
        for(int q=1;q<=5;q++)
        {
            if(c<10)
            {
                k+=c*i;
                break;
            }
            else
            {
                p=c/z;
                k+=p*i;
                c-=p*z;
                z/=10;
                i++;
            }
        }
        if(k%11==h)
        {
            cout<<"Right";
            return 0;
        }
        else
        {
            if(k%11==10)
            {
                cout<<j<<e<<l<<f<<m<<g<<"X";
            }
            else
            {
                cout<<j<<e<<l<<f<<m<<g<<k%11; 
            }   
        }
        return 0;
    } 
    
  • 0
    @ 2019-08-02 10:22:23
    isbn = input()
    i = 1
    y = 0
    for s in isbn:
        if i == 10:
            break
        if s != '-':
            y += int(s) * i
            i += 1
    m = y % 11
    
    if m == 10:
        if isbn[-1] == 'X':
            print('Right')
        else:
            isbn = isbn[0:-1]+'X'
            print(isbn)
    else:
        if str(m) == isbn[-1]:
            print('Right')
        else:
            isbn = isbn[0:-1]+str(m)
            print(isbn)
    
  • 0
    @ 2019-06-12 19:04:00
    //judge the identification code
    #include <iostream>
    #include <vector>
    int main(){
        int sum = 0, sign;
        std::string s;
        std::vector<char> v;
        getline(std::cin, s);
        for(int i = 0; i < s.size(); i++)
            if(s[i] != '-') v.push_back(s[i]);
        for(int i = 1; i <= 9; i++)
            sum += (v[i - 1] - '0') * i;
        sign = sum % 11;
        if(sign == 10 && v[9] == 'X' || sign == v[9] - '0')
            std::cout << "Right" << std::endl;
        else{
            s[s.size() - 1] = (sign == 10 ? 'X' : (sign + 48));
            std::cout << s << std::endl; 
        }
        return 0;
    }
    
  • 0
    @ 2019-01-21 09:53:45

    #include <stdio.h>

    int main()
    {
    char s[20];
    scanf("%s",s);
    int rst=0;
    int a[20];
    int i=0,j=0;
    while(s[j]!=0)
    {
    if(s[j]=='-')
    j++;
    else
    {
    a[i]=s[j]-'0';
    i++,j++;
    }
    }
    int flag1=0,flag2=0;//必须初始化,差点坑在上面
    if(s[j-1]=='X')
    flag1=1;
    for(i=0; i<9; i++)
    rst+=a[i]*(i+1);
    rst=rst%11;
    if(rst==10)
    flag2=1;
    if(a[9]==rst || (flag1==1 && flag2==1))
    printf("Right\n");
    else
    {
    for(i=0; i<12; i++)
    putchar(s[i]);
    if(rst<10)
    printf("%d\n",rst);
    else
    printf("X\n");
    }

    return 0;
    }

  • 0
    @ 2019-01-19 09:44:07

    #include<iostream>
    #include<string>
    using namespace std;

    int main()
    {
    char reg[11]={'0','1','2','3','4','5','6','7','8','9','X'};
    //定义一个数组储存结果0-X
    string ss;
    cin>>ss;
    string::iterator it;//定义指向string类的迭代器,可以理解为指针
    for(it=ss.begin();it!=ss.end();it++){
    if(it=='-'){ss.erase(it);}
    //erase(it)可以理解为删除指向it位置的字符
    }
    int sum=0;
    for(int i=0;i<9;i++){
    sum=sum+(ss[i]-'0')
    (i+1);//字符数字-'0'代表转换成数学数字
    }
    sum=sum%11;
    if(reg[sum]==ss[9]){//如果和最后一位相等,则输出正确
    cout<<"Right"<<endl;
    }
    else{
    cout<<ss[0]<<"-"<<ss[1]<<ss[2]<<ss[3]<<"-"<<ss[4]<<ss[5]<<ss[6]<<ss[7]<<ss[8]<<"-"<<reg[sum]<<endl;
    }
    return 0;
    }

  • 0
    @ 2019-01-19 09:42:57

    #include<iostream>
    #include<string>
    using namespace std;

    int main()
    {
    char reg[11]={'0','1','2','3','4','5','6','7','8','9','X'};
    //定义一个数组储存结果0-X
    string ss;
    cin>>ss;
    string::iterator it;//定义指向string类的迭代器,可以理解为指针
    for(it=ss.begin();it!=ss.end();it++){
    if(it=='-'){ss.erase(it);}
    //erase(it)可以理解为删除指向it位置的字符
    }
    int sum=0;
    for(int i=0;i<9;i++){
    sum=sum+(ss[i]-'0')
    (i+1);//字符数字-'0'代表转换成数学数字
    }
    sum=sum%11;
    if(reg[sum]==ss[9]){//如果和最后一位相等,则输出正确
    cout<<"Right"<<endl;
    }
    else{
    cout<<ss[0]<<"-"<<ss[1]<<ss[2]<<ss[3]<<"-"<<ss[4]<<ss[5]<<ss[6]<<ss[7]<<ss[8]<<"-"<<reg[sum]<<endl;
    }
    return 0;
    }

  • 0
    @ 2019-01-15 13:23:55

    #include<iostream>
    using namespace std;
    int main()
    {
    char a[13];
    cin>>a;
    int sum=0;
    for(int i=0,j=1;i<12;i++)
    {
    if(a[i]!='-')
    {
    sum+=(a[i]-'0')*j;
    j++;
    }

    }
    if(sum%11==10)
    {
    if(a[12]-'0'=='X'-'0')
    {
    cout<<"Right"<<endl;
    }
    else
    {
    for(int y=0;y<12;y++)
    {
    cout<<a[y];
    }
    cout<<'X'<<endl;
    }
    }
    else{
    if(a[12]-'0'==sum%11)
    {
    cout<<"Right"<<endl;
    }
    else
    {
    for(int y=0;y<12;y++)
    {
    cout<<a[y];
    }
    cout<<sum%11<<endl;
    }
    }
    return 0;
    }

    不得不说这个 用反斜杠b还过不了 奇怪了

  • 0
    @ 2019-01-11 18:20:02

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<vector>
    using namespace std;
    char a[14],b[14],t1,t2;
    int t22=0;
    int main()
    {
    scanf("%c-%c%c%c-%c%c%c%c%c-%c",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&t1);
    for(int i=1;i<=9;++i)
    t22+=(a[i]-'0')*i;
    t2=t22%11+'0';
    if(t2=='0'+10)
    t2='X';
    if(t1==t2)
    {
    cout<<"Right";
    return 0;
    }
    cout<<a[1]<<'-'<<a[2]<<a[3]<<a[4]<<'-'<<a[5]<<a[6]<<a[7]<<a[8]<<a[9]<<'-'<<t2;
    return 0;
    }

  • 0
    @ 2018-10-26 20:54:36

    #include<iostream>
    #include<cstdio>
    using namespace std;

    char a[14],b[14],t1,t2;
    int t22=0;

    int main()
    {
    scanf("%c-%c%c%c-%c%c%c%c%c-%c",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&t1);
    for(int i=1;i<=9;++i)
    t22+=(a[i]-'0')*i;
    t2=t22%11+'0';
    if(t2=='0'+10)t2='X';
    if(t1==t2)
    {
    cout<<"Right";
    return 0;
    }
    cout<<a[1]<<'-'<<a[2]<<a[3]<<a[4]<<'-'<<a[5]<<a[6]<<a[7]<<a[8]<<a[9]<<'-'<<t2;
    return 0;
    }

信息

ID
1484
难度
5
分类
字符串 点击显示
标签
递交数
13282
已通过
4678
通过率
35%
被复制
8
上传者