题解

281 条题解

  • 0
    @ 2017-10-24 20:54:11
    ss=raw_input()
    s=ss.replace("-","")
    ans=0
    for i in range(9):
        ans+=int(s[i])*(i+1)
    ans=ans%11
    if ans==10:
        sol="X"
    else:
        sol=ans
    if str(sol)==s[9]:
        print "Right"
    else:
        print ss[:12]+str(sol)
    

    送的

  • 0
    @ 2017-10-22 09:22:11

    #include<stdio.h>
    char a[25];
    int main()
    {
    int s=0,j=1;
    scanf("%s",&a);
    for(int i=0;i<=10;i++)
    {

    if (a[i]=='-');
    else
    {
    s=s+(a[i]-48)*j;j++;
    }
    }
    s=s%11;
    if((s==10)&&(a[12]=='X')||(s==a[12]-48))
    printf("Right\n") ;
    else
    {

    if (s==10)
    a[12]='X';
    else a[12]=s+48;
    printf("%s",a);
    }
    return 0;
    }

  • 0
    @ 2017-10-15 18:54:14

    #include<iostream>
    #include<cstdio>
    #include<string>
    using namespace std;
    int in[14];
    int main()
    {
    int a,b,c,sum;
    char e,f,g,d;
    cin>>a>>e>>b>>f>>c>>g>>d;
    sum=(a*1+b/100*2+b/10%10*3+b%10*4+c/10000*5+c/1000%10*6+c/100%10*7+c/10%10*8+c%10*9)%11;
    if(sum==d-48) {cout<<"Right";return 0;}
    if((sum==10&&d=='X')){
    cout<<"Right";return 0;}
    if(sum!=10)
    cout<<a<<e<<b<<f<<c<<g<<sum;
    if(sum==10)
    cout<<a<<e<<b<<f<<c<<g<<"X";
    return 0;
    }

  • 0
    @ 2017-10-13 23:16:40

    #include<iostream>
    #include<string>
    #include<cctype>
    using namespace std;
    int main() {
    string str;
    cin >> str;
    int key = 0;
    int m = 0;
    for (int i = 0; i < 11; i++)
    {
    if (isdigit(str[i]))
    {
    m++;
    key += (str[i] - '0') * (m);
    }
    }
    if (key % 11 == 10)
    {
    if (str[12] == 'X')
    cout << "Right" << endl;
    else {
    str[12] = 'X';
    cout << str << endl;
    }
    }
    else
    {
    if (str[12] - '0' == key % 11)
    cout << "Right" << endl;
    else
    {
    str[12] = key % 11 + '0';
    cout << str << endl;
    }
    }
    return 0;
    }

  • 0
    @ 2017-10-02 17:20:05
    str1 = input()
    dt = {1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'9',9:'9',10:'X'}
    numlst = [str1[0],str1[2],str1[3],str1[4],str1[6],str1[7],str1[8],str1[9],str1[10]]
    
    numlst1 = list(map(int,numlst))
    
    ids = numlst1[0] + numlst1[1] * 2 +numlst1[2] * 3 +numlst1[3] * 4 +numlst1[4] * 5 +numlst1[5] * 6 +numlst1[6] * 7 +numlst1[7] * 8 +numlst1[8] * 9
    ids = ids%11
    
    if dt[ids] == str1[-1]:
        print('Right')
    else:
        print(str1[:-1]+dt[ids])
    
  • 0
    @ 2017-09-09 19:37:05
    //锻炼细心。。。。
    #include <iostream>
    #include <string>
    #define s ISBN
    
    using namespace std;
    string ISBN;
    inline int todig(char c) { if (c != 'X')return c - '0'; return 10; }
    inline char tochar() { if ((todig(s[0]) + todig(s[2]) * 2 + todig(s[3]) * 3 + todig(s[4]) * 4 + todig(s[6]) * 5 + todig(s[7]) * 6 + todig(s[8]) * 7 + todig(s[9]) * 8 + todig(s[10]) * 9) % 11 != 10)return (todig(s[0]) + todig(s[2]) * 2 + todig(s[3]) * 3 + todig(s[4]) * 4 + todig(s[6]) * 5 + todig(s[7]) * 6 + todig(s[8]) * 7 + todig(s[9]) * 8 + todig(s[10]) * 9) % 11 + '0'; return 'X';}
    int main() {
        cin >> s;
        if ((todig(s[0]) + todig(s[2]) * 2 + todig(s[3]) * 3 + todig(s[4]) * 4 + todig(s[6]) * 5 + todig(s[7]) * 6 + todig(s[8]) * 7 + todig(s[9]) * 8 + todig(s[10]) * 9) % 11 == todig(s[12])) cout << "Right" << endl;
        else cout << s.substr(0, 12) << tochar() << endl;
        return 0;
    }
    
  • 0
    @ 2017-08-22 17:53:00

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {
    int i,sum=0,ans,a10;
    char a[11],bin1,bin2,bin3,ch;
    cin>>a[1]>>bin1>>a[2]>>a[3]>>a[4]>>bin2>>a[5]>>a[6]>>a[7]>>a[8]>>a[9]>>bin3>>a[10];
    for(i=1;i<=9;i++)
    {
    sum+=(a[i]-'0')*i;
    }
    a10=sum%11;
    if(a10<=9)
    {
    ch=a10+'0';
    if(ch==a[10]) cout<<"Right";
    else cout<<a[1]<<bin1<<a[2]<<a[3]<<a[4]<<bin2<<a[5]<<a[6]<<a[7]<<a[8]<<a[9]<<bin3<<ch;
    }
    else
    {
    ch=a10+'N';
    if(ch==a[10]) cout<<"Right";
    else cout<<a[1]<<bin1<<a[2]<<a[3]<<a[4]<<bin2<<a[5]<<a[6]<<a[7]<<a[8]<<a[9]<<bin3<<ch;
    }
    }

  • 0
    @ 2017-08-22 14:08:54

    //isbn号码
    #include<stdio.h>
    #include<ctype.h>
    #include<string.h>
    char isbn[13];
    int main(){
    int sum=0,rec=0;
    scanf("%s",isbn);
    for(int i=0,j=1;i<12;i++){
    if(isdigit(isbn[i])){
    sum+=(isbn[i]-'0')*j;
    j++;
    }
    }
    rec=sum%11;
    if(rec!=10)
    {
    if(rec==isbn[12]-'0')
    {
    printf("Right");
    }
    if(rec!=isbn[12]-'0')
    {
    isbn[12]=rec+'0';
    for(int i=0;i<13;i++)
    {
    printf("%c",isbn[i]);
    }
    }
    }
    /*if(isbn[12]=='X'){
    if(sum%11==10)
    printf("Right");
    else
    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],rec);
    }

    if(isbn[12]-'0'==rec){
    printf("Right");
    }
    else if(rec!=10)
    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],rec);
    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]);
    */
    if(rec==10)
    {
    if(isbn[12]=='X')
    {
    printf("Right");
    }
    if(isbn[12]!='X')
    {
    isbn[12]='X';
    for(int i=0;i<13;i++)
    {
    printf("%c",isbn[i]);
    }
    }
    }
    return 0;
    }

  • 0
    @ 2017-08-14 00:50:24

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std;

    int main(){
    int i,All=0,j;
    char a[12];
    gets(a);
    for(i=0,j=1;i<=10;i++,j++)
    {
    if(i==1||i==5)
    i++;
    All=(a[i]-48)*j+All;
    }
    All=All%11;
    if(All==10)
    {
    if(a[12]=='X')
    printf("Right");
    else
    {
    for(i=0;i<=11;i++)
    printf("%c",a[i]);
    printf("X");
    }
    }
    else
    {
    if(a[12]-48==All)
    printf("Right");
    else
    {
    for(i=0;i<=11;i++)
    printf("%c",a[i]);
    printf("%d",All);
    }
    }
    return 0;
    }

  • 0
    @ 2017-08-12 14:21:55

    s=input()
    a=[]
    tot=0
    for i in range(len(s)-2):
    if s[i]!='-':
    a.append(int(s[i]))
    for i in range(1,10):
    tot+=a[i-1]*i
    fin=str(tot%11)
    if fin=='10':
    fin='X'
    if fin==s[len(s)-1]:
    print('Right')
    else:
    for i in range(len(s)-1):
    print(s[i],end='')
    print(fin)

  • 0
    @ 2017-08-02 17:34:05

    丧心病狂

    #include<iostream>
    using namespace std;
    int num[10];
    char c;
    int main()
    {
        cin>>c;
        num[0]=c-'0';
        cin>>c;
        cin>>c;
        num[1]=c-'0';
        cin>>c;
        num[2]=c-'0';
        cin>>c;
        num[3]=c-'0';
        cin>>c;
        cin>>c;
        num[4]=c-'0';
        cin>>c;
        num[5]=c-'0';
        cin>>c;
        num[6]=c-'0';
        cin>>c;
        num[7]=c-'0';
        cin>>c;
        num[8]=c-'0';
        cin>>c;
        cin>>c;
        if(c=='X')
            num[9]=10;
        else
            num[9]=c-'0';
        if((num[0]+2*num[1]+3*num[2]+4*num[3]+5*num[4]+6*num[5]+7*num[6]+8*num[7]+9*num[8])%11==num[9])
            cout<<"Right";
        else
        {
            num[9]=(num[0]+2*num[1]+3*num[2]+4*num[3]+5*num[4]+6*num[5]+7*num[6]+8*num[7]+9*num[8])%11;
            cout<<num[0]<<"-"<<num[1]<<num[2]<<num[3]<<"-"<<num[4]<<num[5]<<num[6]<<num[7]<<num[8]<<'-';
            if(num[9]==10)
                cout<<"X";
            else
                cout<<num[9];
        }
        return 0;
    }
    
  • 0
    @ 2017-07-24 10:53:01

    pascal 暴力解决..

    var s:string;x,n,i:integer;
    begin
        read(s);
        for i:=1 to 3 do begin
            x:=pos('-',s);
            delete(s,x,1);
        end;
        x:=0;n:=0;
        for i:= 1 to 9 do begin
            val(s[i],x);
            n:=x*i+n;
        end;
        n:=n mod 11;
        if (n=10)and(s[10]='X') then write('Right');
        if (n=10)and(s[10]<>'X')then write(s[1],'-',s[2],s[3],s[4],'-',s[5],s[6],s[7],s[8],s[9],'-','X');
        if n<>10 then begin
            val(s[10],x);
            if x=n then write('Right')
            else write(s[1],'-',s[2],s[3],s[4],'-',s[5],s[6],s[7],s[8],s[9],'-',n);
        end;
    end .
    
  • 0
    @ 2017-07-07 11:52:36
    #include <stdio.h>
    int main(int argc, char const *argv[])
    {
        int num1, num2;
        char num4;
        long int num3;
        scanf("%d-%d-%ld-%c", &num1, &num2, &num3, &num4);
        int s;
        if (num4 == 'X')
        {
            s = 10;
        }
        else
        {
            s = num4 - '0';
        }
        int sum = num1 * 1 + num2 / 100 * 2 + num2 / 10 % 10 * 3 + num2 % 10 * 4;
        sum += (num3/10000)*5 + (num3/1000%10)*6 + (num3/100%10)*7 + (num3%100/10)*8 + (num3%10)*9;
        if (sum%11 == s)
        {
            printf("Right");
        }
        else
        {
            printf("%d-%03d-%05ld-", num1, num2, num3);
            if (sum % 11 == 10)
            {
                printf("X");
            }
            else
            {
                printf("%d", sum % 11);
            }
        }
        return 0;
    }
    
  • 0
    @ 2017-07-07 09:14:03

    #include<iostream>
    using namespace std;
    int main() {
    char a[13];
    int i, sum=0, b,d=1;
    for (i = 0; i < 13; i++)
    cin >> a[i];
    for (i = 0; i < 11; i++){
    if (a[i] != '-'){
    sum+= (a[i] - '0')*d;
    d++;
    }
    }
    b = sum % 11;
    if ((a[12] - '0') == b)
    {
    cout << "Right" << endl;
    }
    else
    {
    a[12] = (b + '0');
    for (i = 0; i < 13; i++)
    cout << a[i];
    cout << endl;
    }
    return 0;
    }

  • 0
    @ 2017-06-03 12:09:16
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    
    char ISBN[20];
    void judge(char isbn[])
    {
        int n;
        int i = 0;
        int index = 0;
        int disnum = 0;
        int t = 0;
        n = strlen(isbn);
        for (i = 0; i < n-1; i++)
        {
            if (isbn[i] == '-')
                continue;
            else
            {
                index++;
                t = t+(isbn[i] - '0')*index;
            }
        }
        disnum = t % 11;
        if (disnum == 10)
        {
            if (isbn[n - 1] == 'X')
                printf("Right\n");
            else
            {
                isbn[n - 1] =  'X';
                printf("%s\n", isbn);
            }
    
        }
        else
        {
            if (disnum == (isbn[n - 1] - '0'))
            {
                printf("Right\n");
            }
            else
            {
                isbn[n - 1] = disnum + '0';
                printf("%s\n", isbn);
            }
        }
        
    }
    int main()
    {
        //freopen("data.in", "r", stdin);
        //freopen("data.out", "w", stdout);
        scanf("%s", ISBN);
        judge(ISBN);
        
        return 0;
    }
    
  • 0
    @ 2017-05-29 00:42:47

    难点在于字符串的分割和拼接以及char和int的转换

    #include<iostream>
    #include<string>
    #include<cstring>
    #include<sstream>
    
    std::string init();
    std::string compute(std::string str);
    
    int main()
    {
        //
        using namespace std;
        string test = init();
        cout << compute(test) << endl;
    
        return 0;
    }
    
    std::string init()
    {
        using namespace std;
    
        string str;
        cin >> str;
        char *temp = new char[str.size()];
        for(int i = 0;i < str.size();i++)
        {
            temp[i] = str[i];
        }
    
        string *result = new string[4];
        result[0] = strtok(temp, "-");
        result[1] = strtok(NULL, "-");
        result[2] = strtok(NULL, "-");
        result[3] = strtok(NULL, "-");
        return result[0] + result[1] + result[2] + result[3];
    }
    
    std::string compute(std::string str)
    {
        using namespace std;
        int temp = 0;
        for(int i = 0;i < 9;i++)
        {
            temp += ((int)(str[i]) - (int)('0')) * (i+1);
        }
    
        if(temp % 11 == 10)
        {
            if(str[9] == 'X')
            {
                return "Right";
            }else
            {
                string result = str;
                result.insert(1, "-");
                result.insert(5, "-");
                result.insert(11, "-");
                result.replace(12, 1, "X");
                return result;
            }
        }else
        {
            if((int)(str[9] - '0') == temp % 11)
            {
                return "Right";
            }else
            {
                string result = str;
                result.insert(1, "-");
                result.insert(5, "-");
                result.insert(11, "-");
                ostringstream oss;
                oss << (temp % 11);
                result.replace(12, 1, oss.str());
                return result;
            }
        }
    }
    
  • 0
    @ 2017-05-18 20:08:38

    #include<iostream>
    #include<string>
    using namespace std;
    int main(){
    string ISBN,ISBN_C;
    int Last_Number=0;
    cin>>ISBN;
    for(int i=0;i<ISBN.length();i++){
    if(ISBN[i]!='-')
    ISBN_C+=ISBN[i];
    }
    for(int i=0;i<ISBN_C.length()-1;i++){
    Last_Number+=(ISBN_C[i]-48)*(i+1);
    }
    Last_Number%=11;
    if(ISBN_C[ISBN_C.length()-1]-48==Last_Number)
    cout<<"Right";
    else if(ISBN_C[ISBN_C.length()-1]=='X'&&Last_Number==10)
    cout<<"Right";
    else {
    ISBN[ISBN.length()-1]=Last_Number+48;
    if(Last_Number==10)
    ISBN[ISBN.length()-1]='X';
    cout<<ISBN;
    }
    return 0;
    }

  • 0
    @ 2017-05-06 18:28:47

    #include <iostream>
    #include <cstdio>
    #include <string.h>
    #include <cmath>
    using namespace std;
    const int maxn = 20;
    char a[maxn];
    int main(){
    scanf("%s",a);
    int t = 1,i;
    int sum = 0;
    for(i=0;i<strlen(a)&&t<=9;i++){
    if(a[i]<='9'&&a[i]>='0'){
    sum += (a[i]-'0')*t;
    t++;
    }
    }
    i++; //跳过间隔符
    sum %= 11;
    if(sum != 10&&sum==(a[i])-'0'){ //识别不是X的情况
    cout<<"Right"<<endl;
    }else if(sum == 10&&a[i]=='X'){ //识别X
    cout<<"Right"<<endl;
    }else{
    if(sum == 10)
    a[i] = 'X';
    else
    a[i] = '0' + sum;
    cout<<a<<endl;
    }
    return 0;
    }

  • 0
    @ 2017-04-23 22:03:37
    #include<stdio.h>
    int main()
    {
        char c1, c2, c3, c4, c5, c6, c7, c8, c9, c10;
        int  n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, rightn10;
        scanf("%c-%c%c%c-%c%c%c%c%c-%c", &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, &c9, &c10); //需要注意这里的输入,只能通过char类型输入.
        n1 = c1 - '0', n2 = c2 - '0', n3 = c3 - '0', n4 = c4 - '0', n5 = c5 - '0', 
            n6 = c6 - '0', n7 = c7 - '0', n8 = c8 - '0', n9 = c9 - '0', n10 = c10 - '0';              //转为int
        rightn10 = (n1 + 2 * n2 + 3 * n3 + 4 * n4 + 5 * n5 + 6 * n6 + 7 * n7 + 8 * n8 + 9 * n9) % 11; //正确的识别码
        if (c10=='X')                 //如果识别符是X的情况
        {
            if (rightn10 == 10) printf("Right");
            else printf("%d-%d%d%d-%d%d%d%d%d-%d", n1, n2, n3, n4, n5, n6, n7, n8, n9, rightn10);
        }
        else                          //识别符不是X的情况,即0~9
        {
            if (rightn10 == 10) printf("%d-%d%d%d-%d%d%d%d%d-X", n1, n2, n3, n4, n5, n6, n7, n8, n9);
            else if (n10 == rightn10) printf("Right");
            else printf("%d-%d%d%d-%d%d%d%d%d-%d", n1, n2, n3, n4, n5, n6, n7, n8, n9, rightn10);
        }
        getchar();
        getchar();
        return 0;
    }
    
  • 0
    @ 2017-04-20 15:54:08
    #include<iostream>
    #include<string>
    #include<cstring>
    using namespace std;
    int main(){
        string isbn;
        int i,j=1,temp = 0;
        cin>>isbn;
        for(i = 0;i<11;i++){
            if(isbn[i]!= '-'){
                temp += (isbn[i] - '0')*j++;
            }
        } 
        temp %= 11;
        if(temp == 10)
            temp = 'X';
        if(temp == (isbn[12] - '0')||(temp == isbn[12]))
            cout<<"Right";
        else{
            if(temp != 'X')
                isbn[12] = (char)(temp+'0');
            else
                isbn[12] = temp;
            cout<<isbn;
        }
        
        return 0;
    }
    

信息

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