题解

267 条题解

  • 6
    @ 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;
    }

  • 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
    @ 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;
    }

  • 0
    @ 2018-09-24 12:26:40
    
    #include<iostream>
    using namespace std;
    char s[14];
    int main()
    {
        cin>>s+1;
        long long a=0;
        a+=((s[1]-'0')*1)%11;
        a+=((s[3]-'0')*2)%11;
        a+=((s[4]-'0')*3)%11;
        a+=((s[5]-'0')*4)%11;
        a+=((s[7]-'0')*5)%11;
        a+=((s[8]-'0')*6)%11;
        a+=((s[9]-'0')*7)%11;
        a+=((s[10]-'0')*8)%11;
        a+=((s[11]-'0')*9)%11;
        a%=11;
        if(a==s[13]-'0'||a==10&&s[13]=='X')
        {
            cout<<"Right";
            return 0;
        }
        for(int i=1;i<=12;i++)
            cout<<s[i];
        if(a==10)
            cout<<'X';
        else cout<<a;
        return 0;
    }
    
    

    暴力AC

  • 0
    @ 2018-07-12 16:19:17

    python版本
    if name == '__main__':
    string = input().split('-')
    s = ''
    sign = 0
    sign1 = ''
    for i in string:
    s += i
    for k in range(9):
    sign += int(s[k])*(k+1)
    if sign % 11 == 10:
    sign1 = 'X'
    else:
    sign1 = str(sign % 11)
    # print(sign1)
    if s[9] == sign1:
    print('Right')
    else:
    print(s[0] + '-' + s[1:4] + '-' + s[4:9] + '-' + sign1)

  • 0
    @ 2018-07-11 21:59:14

    思路:
    1、读入字符串
    2、将除了识别码之外的所有数字符号转化并保存进一个数组当中
    3、将数组内的数字进行乘法并累加
    4、判断并给出正确的ISBN码
    /* This is a program to give the right ISBN. */

    #include <stdio.h>
    #include <string.h>
    int check (int a[9])
    {
    int i, sum = 0, mod;
    for (i = 0; i < 9; i++)
    {
    sum += a[i]*(i + 1);
    }
    mod = sum % 11;
    return mod;
    }
    int main()
    {
    char ch[13];
    int i, j, r, mod, a[9];
    for (i = 0; i < 13; i++)
    {
    scanf ("%c", &ch[i]);
    }
    for (j = 0, i = 0; j < 12; j++)
    {
    r = ch[j] - '0';
    if (r >= 0 && r <= 9)
    {
    a[i] = r;
    i++;
    }
    }
    mod = check (a);
    if (ch[12] - '0' == mod || (mod == 10 && ch[12] == 'X')){
    printf ("Right");
    }else
    {
    if (mod == 10)
    {
    ch[12] = 'X';
    }else
    {
    ch[12] = '0' + mod;
    }
    for (i = 0; i < 13; i++)
    {
    printf ("%c", ch[i]);
    }
    }
    return 0;
    }

  • 0
    @ 2018-07-05 00:41:43

    #include <iostream>
    using namespace std;
    int main(int argc, char** argv)
    {
    string A;
    int a;
    cin>>A;
    a=(A[0]-'0')+(A[2]-'0')*2+(A[3]-'0')*3+(A[4]-'0')*4+(A[6]-'0')*5+(A[7]-'0')*6+(A[8]-'0')*7+(A[9]-'0')*8+(A[10]-'0')*9;
    a=a%11;
    if(A[12]=='X')
    {
    if(a==10) cout<<"Right";
    else cout<<(A[0]-'0')<<'-'<<(A[2]-'0')<<(A[3]-'0')<<(A[4]-'0')<<'-'<<(A[6]-'0')<<(A[7]-'0')<<(A[8]-'0')<<(A[9]-'0')<<(A[10]-'0')<<'-'<<a;
    }
    else
    {
    if(a==(A[12]-'0')) cout<<"Right";
    else
    {
    if(a==10) cout<<(A[0]-'0')<<'-'<<(A[2]-'0')<<(A[3]-'0')<<(A[4]-'0')<<'-'<<(A[6]-'0')<<(A[7]-'0')<<(A[8]-'0')<<(A[9]-'0')<<(A[10]-'0')<<'-'<<'X';
    else cout<<(A[0]-'0')<<'-'<<(A[2]-'0')<<(A[3]-'0')<<(A[4]-'0')<<'-'<<(A[6]-'0')<<(A[7]-'0')<<(A[8]-'0')<<(A[9]-'0')<<(A[10]-'0')<<'-'<<a;
    }
    }
    return 0;
    }

  • 0
    @ 2018-04-14 17:29:36

    其实就是纯模拟,但有很多关键点。以下代码中打“!”表示要重点注意
    ```cpp
    #include<bits/stdc++.h>
    using namespace std ;
    //Vijos P1484

    int x[9] , n , ans ;
    char y , a , b ;
    int main()
    {
    for (int i = 1 ; i <= 5 ; i += 2)//分成三段读入
    {
    for (int j = 0 ; j < i ; j ++)
    {
    cin >> a ;//!一定要用字符型一个一个读入,不然程序会将一整段当成一个整数
    x[n] = a - '0' ;//处理
    ans += x[n] * (n + 1) ;//!一定是(n+1)
    n ++ ;
    }
    cin >> b ;//间隔符
    }
    cin >> y ;//!y是字符型,因为会有“X”
    ans = ans % 11 ;//!对11取余,题目要求
    n = 0 ;
    if ((y - '0' == ans) || ((y == 'X') && (ans == 10)))//!y所表示的数字,或两者都是10
    printf("Right") ;
    else
    {
    for (int i = 1 ; i <= 5 ; i += 2)//分三段
    {
    for (int j = 0 ; j < i ; j ++)
    {
    cout << x[n] ;
    n ++ ;
    }
    cout << b ;
    }
    if (ans == 10)
    cout << "X" ;
    else
    cout << ans ;
    }
    return 0 ;
    }
    ```

信息

ID
1484
难度
5
分类
字符串 点击显示
标签
递交数
12906
已通过
4540
通过率
35%
上传者