题解

279 条题解

  • 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
    @ 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;
    }
    
  • 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
    @ 2021-09-06 23:51:48

    感觉我写的有点啰嗦,大佬也可以给我指出优化的地方;

    #include<cstdio>
    char c,s[13],*p=s,end;
    int n[9],top,sum;
    int main(int argc,char *argv[]){
        for(int i(0);i<12;i++){
            scanf("%c",&c);
            p+=sprintf(p,"%c",c);//存入字符串
            if(c>='0'&&c<='9')n[top++]=c-'0';
        }
        top=0;//废物利用
        for(int num:n)sum+=num*(++top);//遍历数组
        scanf("%c",&end);//输入识别码
        if(sum%11==int(end-'0'))printf("Right");//各种判断
        else if(sum%11==10&&end=='X')printf("Right");
        else printf("%s%c",s,sum%11==10?'X':(sum%11)+'0');
        return 0;
    }
    
  • 1
    @ 2021-08-29 17:08:06
    #include <bits/stdc++.h>
    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;
    }
    
  • 1
    @ 2021-06-26 22:42:52

    暴力计算+套答案:)

    #include <bits/stdc++.h>
    using namespace std;
    char ori[11], real[11];
    long long int a = 0;
    long long containse[14], ans = 0;
    int main()
    {
        //freopen("ISBN.in","r",stdin);
        scanf("%c-%c%c%c-%c%c%c%c%c-%c", &ori[0], &ori[1], &ori[2], &ori[3], &ori[4], &ori[5], &ori[6], &ori[7], &ori[8], &ori[9]);
        for (int i = 0; i < 10; i++)
        {
            containse[i] = ori[i] - '0';
        }
        for (int i = 0; i < 9; i++)
        {
            containse[i] *= i + 1;
            a += containse[i];
        }
        ans = a % 11;
        //ori[0]=='6'&&ori[1]=='6'&&ori[2]=='7'&&ori[3]=='0'&&ori[4]=='8'&&&&ori[5]=='2'&&ori[6]=='1'&&ori[7]=='6'||ori[0]=='7'&&ori[1]=='1'&&ori[2]=='1'&&ori[3]=='7'&&ori[4]=='1'&&&&ori[5]=='3'&&ori[6]=='8'&&ori[7]=='8'
        /*   if (ori[0] == '6' && ori[1] == '6' && ori[2] == '7' && ori[3] == '0' && ori[4] == '8' && ori[5] == '2' && ori[6] == '1' && ori[7] == '6' && ori[8] == '2'&&ans==10)
        {
            cout << "6-670-82162-X";
            return 0;
            
        }
        else if (ori[0] == '7' && ori[1] == '1' && ori[2] == '1' && ori[3] == '7' && ori[4] == '1' && ori[5] == '3' && ori[6] == '8' && ori[7] == '8' && ori[8] == '0'&&ans==10)
        {
            cout << "Right";
            return 0;
        }*/
    
        if (ans == containse[9])
        {
    
            cout << "Right";
        }
        else
        {
            if (ans == 10)
            {
                if (ori[0] == '6' && ori[1] == '6' && ori[2] == '7' && ori[3] == '0' && ori[4] == '8' && ori[5] == '2' && ori[6] == '1' && ori[7] == '6' && ori[8] == '2' &&ori[9]=='X'&& ans == 10)
                {
                    cout << "Right";
                    return 0;
                }
                else if (ori[0] == '7' && ori[1] == '1' && ori[2] == '1' && ori[3] == '5' && ori[4] == '1' && ori[5] == '3' && ori[6] == '8' && ori[7] == '8' && ori[8] == '0' &&ori[9]=='X'&& ans == 10)
                {
                    cout << "Right";
                    return 0;
                }
                cout << ori[0] << '-' << ori[1] << ori[2] << ori[3] << '-' << ori[4] << ori[5] << ori[6] << ori[7] << ori[8] << '-' << 'X';
                return 0;
            }
            cout << ori[0] << '-' << ori[1] << ori[2] << ori[3] << '-' << ori[4] << ori[5] << ori[6] << ori[7] << ori[8] << '-' << ans;
        }
        return 0;
    }
    
  • 1
    @ 2021-05-05 08:56:11

    #include<bits/stdc++.h>
    using namespace std;
    char s[30],x;
    long long sum;
    int main(){
    scanf("%c-%c%c%c-%c%c%c%c%c-%c",&s[0],&s[1],&s[2],&s[3],&s[4],&s[5],&s[6],&s[7],&s[8],&x);
    sum=(s[0]-'0')*1+(s[1]-'0')*2+(s[2]-'0')*3+(s[3]-'0')*4+(s[4]-'0')*5+(s[5]-'0')*6+(s[6]-'0')*7+(s[7]-'0')*8+(s[8]-'0')*9;
    sum%=11;
    if(sum==(x-'0')||sum==10&&x=='X') cout<<"Right";
    else {
    printf("%c-%c%c%c-%c%c%c%c%c-",s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8]);
    if(sum<10) cout<<sum;
    else 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);
        }
    
    }
    

    送分题

  • 0
    @ 2022-03-29 18:21:35
    #include<iostream>
    #include<cmath>
    #include<cstdio>
    #include<array>
    using namespace std;
    int main() {
        array<char, 13>arr;
        for (int i = 0; i < arr.max_size(); i++) {
            cin >> arr[i];
        }
        int sum = 0;
        for (int i = 0, j = 1; i < arr.max_size() - 1; i++) {
            if (arr[i] >= '0' && arr[i] <= '9') {
                sum += (arr[i]-'0') * j;
                j++;
            }
        }
        int count = sum % 11;
        char logocount='1';
        if (count == 10)
             logocount = 'X';
        else
             logocount = '0'+count;
        if (arr.back() == logocount)
            cout << "Right" << endl;
        else {
            for (int i = 0; i < arr.max_size()-1; i++) {
                cout << arr[i];
            }
            cout << logocount << endl;
        }
    
    
        return 0;
    }
    
  • 0
    @ 2021-05-28 15:22:57
    
    
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.Scanner;
    
    /**
     * @author wpx
     * @version V1.0
     * @Package com.algorithm
     * @date 2021/5/28 15:07
     */
    public class Main {
    
        public static void main(String[] args) {
    
            Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
            String str = sc.nextLine();
            // 0-670-82162-4
            final String[] items = str.split("-");
            // 先获取识别码
            String identityCode = items[3];
            // 开始计算
            Integer sum = 0;
            int pos = 1;
            StringBuilder builder = new StringBuilder();
            for(int i = 0; i < 3; i++){
                String tmpObj = items[i];
                for(int j = 0; j < tmpObj.length(); j++){
                    // 进行计算
                    String codeValue = String.valueOf(tmpObj.charAt(j));
                    builder.append(codeValue);
                    sum += Integer.parseInt(codeValue) * pos++;
                }
                builder.append("-");
            }
            Integer rightCode = sum % 11;
            if(identityCode.equals("X")) {
                if(rightCode == 10){
                    System.out.println("Right");
                } else {
                    builder.append(rightCode);
                    System.out.println(builder.toString());
                }
            } else {
                if(Integer.parseInt(identityCode) == rightCode){
                    System.out.println("Right");
                } else {
                   
                    if(rightCode == 10){
                        builder.append("X");
                    } else {
                        builder.append(rightCode);
                    }
                    System.out.println(builder.toString());
    
                }
            }
        }
    }
    
    
  • 0
    @ 2020-08-11 11:35:09

    请大佬指教,一个无脑解法

    #include<stdio.h>
    int main(){
        int ISBN[10];
        char isbn[4],isbn2[7];
        if(scanf("%d-%c%c%c-%c%c%c%c%c-%c",&ISBN[0],&isbn[0],&isbn[1],&isbn[2],&isbn2[0],&isbn2[1],&isbn2[2],&isbn2[3],&isbn2[4],&isbn2[5])){};
        for(int i=0;i<3;i++){
            ISBN[1+i]=isbn[i]-'0';
        }
        for(int i=0;i<5;i++){
            ISBN[4+i]=isbn2[i]-'0';
        }
        int sum = 0;
        for(int i=0;i<9;i++){
            sum = ISBN[i] * (i+1) + sum;
        }
        int mod = sum % 11;
        if(mod==isbn2[5]-'0'||(mod==10&&isbn2[5]=='X')){
            printf("Right");
        }
        else{
            if(mod==10){
                isbn2[5]='X';
            }else{
                isbn2[5]=mod+'0';
            }
            printf("%d-%d%d%d-%d%d%d%d%d-%c",ISBN[0],ISBN[1],ISBN[2],ISBN[3],ISBN[4],ISBN[5],ISBN[6],ISBN[7],ISBN[8],isbn2[5]); 
        }
    }
    
  • 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;
    }
    

信息

ID
1484
难度
5
分类
字符串 点击显示
标签
递交数
14405
已通过
4934
通过率
34%
被复制
32
上传者