题解

281 条题解

  • 0
    @ 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
    @ 2017-03-10 21:17:29

    #include<stdio.h>
    int main()
    {
    int sum=0;
    int a;
    char isbn[13];
    scanf("%s-%s%s%s-%s%s%s%s%s-%s",&isbn[0],&isbn[1],&isbn[2],&isbn[3],&isbn[4],&isbn[5],&isbn[6],&isbn[7],&isbn[8],&isbn[9],&isbn[10],&isbn[11],&isbn[12]);
    sum+=((isbn[0]-48)*1);
    sum+=((isbn[2]-48)*2);
    sum+=((isbn[3]-48)*3);
    sum+=((isbn[4]-48)*4);
    sum+=((isbn[6]-48)*5);
    sum+=((isbn[7]-48)*6);
    sum+=((isbn[8]-48)*7);
    sum+=((isbn[9]-48)*8);
    sum+=((isbn[10]-48)*9);
    a=sum%11;
    if(a==10)
    {
    a='X'-88;
    }
    if((a==isbn[12]-48)&&(a!='X'-88)||(a==isbn[12]-88)&&(a=='X'-88))
    printf("Right");
    else if(a!='X'-88)
    {
    printf("%c-%c%c%c-%c%c%c%c%c-%d",isbn[0],isbn[2],isbn[3],isbn[4],isbn[6],isbn[7],isbn[8],isbn[9],isbn[10],a);
    }
    else
    {
    printf("%c-%c%c%c-%c%c%c%c%c-X",isbn[0],isbn[2],isbn[3],isbn[4],isbn[6],isbn[7],isbn[8],isbn[9],isbn[10]);
    }
    }

  • 0
    @ 2017-02-28 22:41:53

    #include <stdio.h>

    int main()
    {
    char s[10000];
    int i;
    int sum=0;
    int a;
    int b = 1;
    for(i=0;i<13;i++)
    {
    scanf("%c",&s[i]);
    }
    for(i=0;i<11;i++)
    {
    if(s[i]!='-')
    sum+=(s[i]-48)*(b++);
    }
    a = sum % 11;
    if(a==10)
    {
    if(s[12]=='X')
    printf("Right");
    else
    {
    s[12] = 'X';
    printf("%s",s);
    }
    }
    else if(a==(s[12]-48))
    printf("Right");
    else
    {
    s[12] = a+48;

    printf("%s",s);
    }
    return 0;
    }

  • 0
    @ 2017-02-27 19:23:19
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    char str[100];
    int sum=0;
    int main(){
        for(int i = 1; i<=13;i++){
            str[i]=getchar();
        }
    //  cin>>str+1;
        sum+=(str[1]-'0')*1;
        sum+=(str[3]-'0')*2;
        sum+=(str[4]-'0')*3;
        sum+=(str[5]-'0')*4;
        sum+=(str[7]-'0')*5;
        sum+=(str[8]-'0')*6;
        sum+=(str[9]-'0')*7;
        sum+=(str[10]-'0')*8;
        sum+=(str[11]-'0')*9;
        sum = sum%11;
        if(sum==str[13]-'0'||sum==10&&str[13]=='X'){
            cout<<"Right"<<endl;
        }else{
            if(sum==10){
                str[13]='X';
                
            }else{
                str[13]='0'+sum;
            }
            cout<<str+1<<endl;
        }
        return 0;   
    } 
    
  • 0
    @ 2017-02-23 19:36:35

    当求余之后为10的时候需要判断 标识位是否为‘X’这很重要 ::::~~~!!!!@@@@

    #include <iostream>

    using namespace std;
    int main()
    {
    int i=0,j=1,s=0;
    char str[14];
    cin >> str;
    while(i<12)
    {
    if(str[i] >= '0' && str[i] <= '9')
    {
    s = s + (str[i] - '0') * j;
    j++;
    }
    i++;
    }
    str[i+1] = '\0';
    if(s%11 == (str[i] - '0'))
    cout << "Right" <<endl;
    else if((s%11 == 10)&&(str[i] == 'X'))
    cout << "Right" <<endl;
    else if(s%11 == 10)
    {
    str[i] = 'X';
    cout << str << endl;
    }
    else
    {
    str[i] = s%11 + '0';
    cout << str << endl;
    }
    return 0;
    }

  • 0
    @ 2017-02-19 21:01:17

    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<set>
    #include<stack>
    #include<sstream>
    #include<map>
    #include<vector>
    #include<queue>
    using namespace std;
    string isbn;
    int main(){
    cin>>isbn;
    int cnt;
    cnt+=(isbn[0]-'0')*1;
    cnt+=(isbn[2]-'0')*2;
    cnt+=(isbn[3]-'0')*3;
    cnt+=(isbn[4]-'0')*4;
    cnt+=(isbn[6]-'0')*5;
    cnt+=(isbn[7]-'0')*6;
    cnt+=(isbn[8]-'0')*7;
    cnt+=(isbn[9]-'0')*8;
    cnt+=(isbn[10]-'0')*9;
    if(isbn[12]=='X'&&cnt%11==10) cout<<"Right"<<endl;
    else if(isbn[12]-'0'==cnt%11) cout<<"Right"<<endl;
    else
    {
    for(int i=0;i<=11;i++)
    printf("%c",isbn[i]);
    if(cnt%11==10) cout<<"X"<<endl;
    else printf("%d\n",cnt%11);
    }

    return 0;
    }

  • 0
    @ 2017-02-07 17:11:36
    #include<iostream>
    using namespace std;
    int main()
    {
        char a[20] = {};
        cin.getline(a, 15);
        int b[15] = {};
    
        b[1] = a[0] - '0';
        b[2] = a[2] - '0';
        b[3] = a[3] - '0';
        b[4] = a[4] - '0';
        b[5] = a[6] - '0';
        b[6] = a[7] - '0';
        b[7] = a[8] - '0';
        b[8] = a[9] - '0';
        b[9] = a[10] - '0';
        /*for (int i = 1; i <= 9; i++)
        {
            cout << b[i];
        }*/
        int stdan = 0;
        for (int i = 1; i < 10; i++)
        {
    
            stdan += (b[i] * i);
        }
        //cout << stdan << endl;
        stdan %= 11;
        //cout << stdan << endl;
        if (stdan == 10)
        {
            //cout << "stdan == 10" << endl;
            if (a[12] == 'X')
                cout << "Right" << endl;
            else
            {
                cout << b[1] << '-' << b[2] << b[3] << b[4];
                cout << '-' << b[5] << b[6] << b[7] << b[8] << b[9] << '-';
                cout << 'X' << endl;
            }
        }
        else
        {
            // cout << std;
            // cout << a[12] << endl;
            int temp = (a[12] - 48);
            // cout << "temp = " << temp << endl;
            if (temp == stdan)
            {
                //cout << stdan;
                cout << "Right" << endl;
            }
            else
            {
                cout << b[1] << '-' << b[2] << b[3] << b[4];
                cout << '-' << b[5] << b[6] << b[7] << b[8] << b[9] << '-';
                cout << stdan << endl;
            }
            //temp = '0';
            //cout << temp;
            system("pause");
            return 0;
    
        }
    }
    
  • 0
    @ 2017-01-22 14:13:59

    c++代码:

    #include<iostream>
    #include<cstring>
    using namespace std;//头文件
    int main()
    {
    char s[20]; //isbn号码需要使用的字符串
    int i,ans=0,sum=0;
    cin>>s;//输入isbn号码
    for(i=0;i<=11;i++){
    if(s[i]>=48&&s[i]<=57){
    sum++;//数字的位数
    ans+=sum*(s[i]-48);//累乘计算mod前的值
    }
    else continue;//遇到“-”不处理
    }
    ans%=11;//mod11得到isbn的识别码
    ans+=48;//转换为ASCII码
    if(ans==58) ans='X';//处理“X”
    if(ans==s[12]) cout<<"Right"<<endl;//判断是否正确
    else {
    s[12]=ans;//将正确的值赋给最后一位
    for(i=0;i<=12;i++) cout<<s[i];//输出正确的值
    cout<<endl;
    }
    return 0;
    }

  • 0
    @ 2017-01-20 00:33:19

    卧槽。。。。。。。。。。拿这个题恢复一下手感,寒假刚开始堕落。。。。做题挽救下自己
    ```c++
    #include<cstdio>
    #include<algorithm>
    #include<cstdlib>
    #include<cstring>
    int main()
    {
    char s[13];
    scanf("%s",s);
    int c = (s[0]-'0') + (s[2]-'0')*2+(s[3]-'0')*3+(s[4]-'0')*4+(s[6]-'0')*5+(s[7]-'0')*6+(s[8]-'0')*7+(s[9]-'0')*8+(s[10]-'0')*9;
    //对余数为10特殊处理
    if(c%11 == 10)
    {
    if(s[12] == 'X')printf("Right");
    else
    {
    s[12] = 'X';
    printf("%s",s);
    }
    }
    else
    {
    if((s[12]-'0') == c%11) printf("Right");
    else
    {
    s[12] = c%11+'0';
    printf("%s",s);
    }
    }
    return 0 ;
    }

  • 0
    @ 2016-11-17 15:48:05

    比起立体图来,这个简单多了!
    代码仅供参考,最好**不要**ctrlC+ctrlV照搬!
    ```c++
    #include <bits/stdc++.h>
    using namespace std;

    int main()
    {
    string str;
    char ch;
    int i,n=1,sum=0;
    getline(cin,str);
    for(i=0;i<11;i++)
    if(i!=1&&i!=5)
    {
    sum=sum+(str[i]-48)*n;
    n++;
    }
    sum=sum%11;
    if(sum==10) ch='X';
    else ch=sum+48;
    if(str[12]==ch) cout<<"Right"<<endl;
    else
    {
    for(i=0;i<12;i++) cout<<str[i];
    cout<<ch<<endl;
    }
    return 0;
    }
    ```

  • 0
    @ 2016-11-17 15:46:19

    比起立体图来,这个简单多了!
    代码仅供参考,最好**不要**ctrlC+ctrlV照搬!

    ···c++
    #include <bits/stdc++.h>
    using namespace std;

    int main()
    {
    string str;
    char ch;
    int i,n=1,sum=0;
    getline(cin,str);
    for(i=0;i<11;i++)
    if(i!=1&&i!=5)
    {
    sum=sum+(str[i]-48)*n;
    n++;
    }
    sum=sum%11;
    if(sum==10) ch='X';
    else ch=sum+48;
    if(str[12]==ch) cout<<"Right"<<endl;
    else
    {
    for(i=0;i<12;i++) cout<<str[i];
    cout<<ch<<endl;
    }
    return 0;
    }
    ```

  • 0
    @ 2016-11-10 20:18:58

    #include <stdio.h>
    #include <stdlib.h>

    char a[15],b[15];
    main(){

    int i = 1,k = 1,ans = 0;
    char c;
    while((c = getchar()) != '\n'){

    a[i] = c;
    i ++;
    }
    char x[10] = {'0','1','2','3','4','5','6','7','8','9'};
    for(i = 1;i <= 12;i ++)
    {
    for(int j = 0;j <= 9;j ++)
    {
    if(a[i] == x[j]){
    ans += j*k;
    k++;
    }
    }
    }
    ans = ans%11;
    if(ans == 10)
    {
    if(a[13] == 'X')
    printf("Right");
    else
    {
    a[13] = 'X';
    for(i = 1;i <= 13;i ++)
    printf("%c",a[i]);
    }
    }
    else {
    int tail;
    for(i = 0;i <= 9;i ++)
    {
    if(a[13] == x[i])
    tail = i;
    }
    if(ans == tail){
    printf("Right");
    }
    if(ans != tail){
    for(i = 1;i <= 12;i ++)
    printf("%c",a[i]);
    printf("%d",ans);
    }
    }
    }

  • 0
    @ 2016-10-21 21:16:19

    #include <cstdio>
    #include <cstdlib>
    #include <iostream>

    using namespace std;

    int main()
    {

    string s;
    cin >> s;

    int num(0);

    for (int i(0),j(1); i < 12; i++)
    if( s[i] != '-')
    num += (s[i] - '0') * j++;

    if(s[12] == 'X' && num % 11 == 10 || (s[12] -'0') == num % 11)
    cout << "Right";
    else if(num % 11 == 10){

    s[12] = 'X';
    cout<< s;

    }else{

    s[12] += num % 11 - (s[12] - '0');
    cout << s;
    }

    }
    //2333333333333

  • 0
    @ 2016-10-20 19:20:17
    #include<iostream>
    #include<string>
    using namespace std;
    int main(){
        string s;
        cin>>s;
        int tot(0);
        char mod[12]="0123456789X";
        for(int i(0),j(1);i<12;i++){
            if(s[i]=='-')continue;
            tot+=(s[i]-'0')*j++;
        }
        if(mod[tot%11]==s[12])cout<<"Right";
        else s[12]=mod[tot%11],cout<<s;
        return 0;
    }
    
  • 0
    @ 2016-10-08 01:04:49

    #include <iostream>
    #include <cstdio>

    using namespace std;

    int main()
    {
    char a[10];
    char ans;
    int i, temp = 0;
    scanf("%c-%c%c%c-%c%c%c%c%c-%c", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9]);
    for(i=1;i<=9;++i)
    temp+=((int)a[i-1]-48)*i;
    temp%=11;
    if(temp==10)temp='X'-48;
    if((char)(temp+48)==a[9])cout<<"Right";
    else printf("%c-%c%c%c-%c%c%c%c%c-%c", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], temp+48);
    // system("pause");
    return 0;
    }

  • 0
    @ 2016-10-08 01:04:34

    #include <iostream>
    #include <cstdio>

    using namespace std;

    int main()
    {
    char a[10];
    char ans;
    int i, temp = 0;
    a[0]=getchar();
    getchar();
    a[1]=getchar();
    a[2]=getchar();
    a[3]=getchar();
    getchar();
    a[4]=getchar();
    a[5]=getchar();
    a[6]=getchar();
    a[7]=getchar();
    a[8]=getchar();
    getchar();
    a[9]=getchar();
    for(i=1;i<=9;++i)
    temp+=((int)a[i-1]-48)*i;
    temp%=11;
    if(temp==10)temp='X'-48;
    if((char)(temp+48)==a[9])cout<<"Right";
    else printf("%c-%c%c%c-%c%c%c%c%c-%c", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], temp+48);
    // system("pause");
    return 0;
    }

  • 0
    @ 2016-09-11 22:24:28

    代码
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    char a[14];
    int main()
    {
    scanf("%s",a);
    int n=1;
    int ans=0;
    for(int i=0;i<=11;i++)
    {
    if(a[i]!='-')
    {
    ans=ans+(a[i]-'0')*n;
    n++;
    }
    }
    ans=ans%11;
    if(ans!=10)
    {
    if(ans==a[12]-'0')
    {
    printf("Right");
    }
    else
    {
    for(int i=0;i<=11;i++)
    {
    printf("%c",a[i]);
    }
    printf("%d",ans);
    }

    }
    else
    {
    if(a[12]=='X')
    {
    printf("Right");
    }
    else
    {
    for(int i=0;i<=11;i++)
    {
    printf("%c",a[i]);
    }
    printf("X");
    }
    }
    }

  • 0
    @ 2016-09-05 11:34:23
    pascal
    var s:string;
    t,i,j:longint;
    begin
     readln(s);
     j:=1;
     for i:=1 to length(s)-2 do
     begin
      if(s[i]>='0')and(s[i]<='9')
      then begin
       t:=t+(ord(s[i])-ord('0'))*j;
       inc(j);
      end;
     end;
     t:=t mod 11;
     if(ord(s[length(s)])-ord('0')=t)or((t=10)and(s[length(s)]='X'))
     then writeln('Right')
     else begin
      if(t=10)then s[length(s)]:='X'
      else s[length(s)]:=chr(ord('0')+t);
      writeln(s);
     end;
    end.
    
  • 0
    @ 2016-07-27 21:43:30

    正则水过。人生苦短,我用python
    ```python
    import re

    m = re.match(r'(\d)-(\d{3})-(\d{5})-(\w)', raw_input())
    x = m.group(1)+m.group(2)+m.group(3)
    if m.group(4) == 'X':
    gt = 10
    else:
    gt = int(m.group(4))-int('0')
    rk = 1
    ans = 0
    for i in x:
    ans += rk*(int(i)-int('0'))
    rk += 1
    if ans%11 == gt:
    print "Right"
    else:
    if ans%11 == 10:
    res = 'X'
    else:
    res = str(ans%11)
    print m.group(1)+'-'+m.group(2)+'-'+m.group(3)+'-'+res
    ```

  • 0
    @ 2016-07-13 17:18:08

    #include <cstdio>

    int main(){
    freopen("in.txt","r",stdin);
    int a[11],sum=0;
    char c;
    scanf("%1d-%1d%1d%1d-%1d%1d%1d%1d%1d-%c",
    &a[1],&a[2],&a[3],&a[4],&a[5],
    &a[6],&a[7],&a[8],&a[9],&c);
    for(int i=1;i<=9;i++)
    sum+=i*a[i];
    sum%=11;
    int flag=0;
    if(sum==c-'0'||(c=='X'&&sum==10)){
    printf("Right");
    return 0;
    }
    printf("%d-%d%d%d-%d%d%d%d%d-",
    a[1],a[2],a[3],a[4],a[5],
    a[6],a[7],a[8],a[9]);
    if(sum==10)
    printf("X");
    else
    printf("%d",sum);
    return 0;
    }

信息

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