题解

281 条题解

  • 0
    @ 2016-05-20 19:55:54

    #include <iostream>
    #include <cstdio>
    #include <string>
    using namespace std;
    int main()
    {
    string c;
    cin >> c;
    int s = 0;
    int k = 1;

    for (int i = 0; i < c.size()-1; i++)
    {
    if (c[i] >= '0'&&c[i] <= '9')
    {
    /*cout <<c[i];*/
    /*cout << k;*/
    s = s + (c[i] - '0')*k;
    k++;
    }
    }
    int dd= c.size() - 1;
    int vis = s % 11;
    if (vis == c[dd] - '0')
    {
    cout << "Right" << endl;
    }
    else
    {
    if (vis == 10&& c[dd] == 'X')
    {
    cout << "Right" << endl;
    }
    else
    {
    for (int i = 0; i < c.size() - 1; i++)
    {
    cout << c[i];
    }
    if (vis == 10)
    {
    cout << "X" << endl;
    }
    else
    {
    cout << vis << endl;
    }
    }
    }
    return 0;
    }

  • 0
    @ 2016-04-21 20:31:31

    50次终于AC....输入数据坑人啊!!!!!!!!
    第4个点和第7个点输入的识别码是X!
    对没错,也就是说需要在原来程序的基础上添加判断输入数据是X的判定
    var st:string;
    a:array[1..10]of longint;
    i,j,t,s:longint;
    begin
    readln(st);s:=0;
    delete(st,2,1);
    delete(st,5,1);
    delete(st,10,1);
    for i:=1 to 9 do
    a[i]:=ord(st[i])-48;
    if st[10]='X' then a[10]:=10 else a[10]:=ord(st[10])-48;
    for i:=1 to 9 do
    s:=s+a[i]*i;
    if s mod 11=a[10] then begin writeln('Right');exit;end else
    if s mod 11=10 then
    writeln(a[1],'-',a[2],a[3],a[4],'-',a[5],a[6],a[7],a[8],a[9],'-','X') else
    writeln(a[1],'-',a[2],a[3],a[4],'-',a[5],a[6],a[7],a[8],a[9],'-',s mod 11);
    end.

  • 0
    @ 2016-03-14 17:08:57

    #include<iostream>
    using namespace std;
    char a[18];
    int b,sum;
    int main()
    {
    //freopen("p.in","r",stdin);
    //freopen("p.out","w",stdout);
    cin>>a;
    b=((a[0]-'0')*1+(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)%11;

    if (b==10&&a[12]=='X')

    {
    cout<<"Right";
    return 0;
    }
    if(a[12]-'0'==b)
    {
    cout<<"Right";
    return 0;
    }
    else
    {
    for(int i=0;i<12;i++) cout<<a[i];
    if (b==10) cout<<'X';
    else cout<<b;
    }
    return 0;
    }
    //c++

  • 0
    @ 2016-02-19 21:26:44

    注意还有一个X的情况
    c
    #include <stdio.h>
    #define toint(x) (int)((x)-48)
    int main(){
    char isbn[50];
    int i,vari = 0,cur;
    scanf("%s",isbn);
    for(i = 0,cur = 1;i<12;i++,cur++){
    vari += (toint(isbn[i]) * cur);
    if(i<11) {
    if(isbn[i+1]=='-') i++;
    }
    }
    vari %= 11;
    if(vari!=10?isbn[12] == (vari + 48):isbn[12] == 'X') printf("Right\n");
    else{
    isbn[12] = vari == 10?'X':(vari+48);
    printf("%s\n",isbn);
    }
    return 0;
    }

  • 0
    @ 2016-02-18 18:40:13

    题目中没有说 余数是10的情况,上网搜了一下,余数为10的用'X‘代替
    ```
    /* ***********************************************
    Author :guanjun
    Created Time :2016/2/18 18:17:28
    File Name :vijosp1484.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;

    bool cmp(int a,int b){
    return a>b;
    }
    int a[11];
    int main()
    {
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    string s,t,p;
    while(cin>>s){
    t=s;
    int num=0;
    for(int i=0;i<s.size();i++){
    if(s[i]!='-')
    if(s[i]=='X')a[++num]=10;
    else a[++num]=int(s[i]-'0');
    }
    int sum=0;
    for(int i=1;i<=num-1;i++){
    sum+=a[i]*i;
    }
    //cout<<sum<<endl;
    sum%=11;
    if(sum==a[num]){
    puts("Right");
    }
    else{
    if(sum<10)
    t[t.size()-1]=char(sum+'0');
    else t[t.size()-1]='X';
    cout<<t<<endl;
    }
    }
    return 0;
    }

  • 0
    @ 2016-01-07 19:36:58

    var
    s:string[13];
    a:array[1..9]of 0..9;
    i,t,n:longint;
    b:boolean;
    begin
    {assign(input,'isbn.in');
    reset(input);
    assign(output,'isbn.out');
    rewrite(output);}
    readln(s);
    fillchar(a,sizeof(a),0);
    delete(s,2,1);
    delete(s,5,1);
    delete(s,10,1);
    for i:=1 to 9 do
    a[i]:=ord(s[i])-48;
    if s[10]='X' then n:=10
    else n:=ord(s[10])-48;
    t:=0;
    for i:=1 to 9 do
    t:=t+i*a[i];
    t:=t mod 11;
    b:=true;
    if t=n then begin
    writeln('Right');
    b:=false;
    end;
    if b then write(a[1],'-',a[2],a[3],a[4],'-',a[5],a[6],a[7],a[8],a[9],'-');
    if b then begin
    if t=10 then writeln('X')
    else writeln(t);
    end;
    {close(input);
    close(output);}
    end.

  • 0
    @ 2015-12-15 00:20:21

    C Code

    #include<stdio.h>
    int main()
    {
    char isbni[14];
    int isbn[9];
    // FILE *in=fopen("isbn.in","r"),*out=fopen("isbn.out","w");
    int i,p=0,tol=0,last;
    // fscanf(in,"%s",isbni);
    scanf("%s",isbni);
    for(i=0;i<=11;i++)
    if(isbni[i]!='-')
    {
    isbn[p]=isbni[i]-48;
    p++;
    }
    for(i=0;i<=8;i++)
    tol+=isbn[i]*(i+1);
    tol%=11;
    if(isbni[12]!='X')
    last=isbni[12]-48;
    else
    last=10;
    if(last==tol)
    printf("Right");
    else
    {
    if(tol==10)
    isbni[12]='X';
    else
    isbni[12]=tol+48;
    printf("%s",isbni);
    }
    // fclose(out);
    return 0;
    }

  • 0
    @ 2015-11-02 20:02:46

    so easy!

    var s:string;
    i,x:integer;
    y:int64;
    a:array[1..13] of integer;
    begin
    readln(s);
    for i:=1 to 12 do
    if s[i]<>'-' then begin inc(x); a[x]:=ord(s[i])-ord('0'); end;
    if (s[13]='x') or (s[13]='X') then a[x+1]:=10
    else a[x+1]:=ord(s[13])-ord('0');
    for i:=1 to x do y:=y+a[i]*i;
    y:=y mod 11;
    if y=a[x+1] then writeln('Right')
    else
    begin
    if y=10 then s[13]:='X'
    else s[13]:=chr(y+ord('0'));
    writeln(s);
    end;
    end.

  • 0
    @ 2015-10-23 22:56:57

    不解,为什么不能AC?

    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    int main()
    {
    char input1[64];
    int weight = 1;
    int h=0;
    int sum1 = 0;
    char *p;
    FILE * fp;
    FILE * fout;
    fp = fopen("isbn.in","r");
    fout=fopen("isbn.out","w");
    fscanf(fp,"%s",input1);
    p = input1;
    while (*p!=0 && h<3)
    {
    if (*p=='-')
    {
    h++;
    p++;
    continue;
    }
    sum1 +=(*p++-'0')*weight;
    weight++;
    }
    int y =sum1%11;

    if(y==10)
    {
    if (*p=='X')
    {
    //printf("Right");
    fprintf(fout,"Right");
    }else if(*p!='X')
    {
    *p='X';
    fprintf(fout,"%s",input1);
    //printf("%s",input1);
    }
    }
    else if ((*p-'0')==y && *p<='9')
    fprintf(fout,"Right");
    //printf("Right");
    else
    {
    fix1:
    *p=y+'0';
    //printf("%s",input1);
    fprintf(fout,"%s",input1);
    }
    fclose(fout);
    fclose(fp);
    }

  • 0
    @ 2015-08-26 19:47:08

    只要注意X的特判就行了,也没什么难度。
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    using namespace std;
    int main()
    {
    char a[15];
    int b[15],c[15],i,j=1,s=0,n;
    for(i=1;i<=13;i++){
    cin>>a[i];
    if(a[i]=='X')
    b[i]=10;
    else
    b[i]=a[i]-48;
    c[i]=b[i];
    }
    for(i=1;i<=9;i++){
    if(b[j]<0||b[j]>9){
    j++;
    }
    b[j]*=i;
    s+=b[j];
    j++;
    }
    n=s%11;
    if(n==c[13]){
    cout<<"Right";
    }
    else{
    c[13]=n;
    for(j=1;j<=13;j++){
    if(j==2||j==6||j==12){
    cout<<"-";
    }

    else{
    if(c[j]==10){
    cout<<"X";
    break;
    }
    cout<<c[j];
    }
    }
    }
    return 0;
    }

  • 0
    @ 2015-08-11 09:32:30

    var
    i,j,k,l,m,n,ans:longint;
    s:string;
    a,b:array[1..20] of longint;
    begin
    read(s);
    for i:=1 to 12 do
    if (s[i]<>'-') then
    begin
    j:=j+1;
    a[j]:=ord(s[i])-48;
    end;
    for j:=1 to 9 do
    begin
    ans:=ans+a[j]*j;
    end;
    n:=ans mod 11;
    if n=10 then
    if s[13]='X' then write('Right') else
    begin
    for i:=1 to 12 do write(s[i]);
    write('X');
    end
    else
    if n=ord(s[13])-48 then write('Right')
    else
    begin
    for i:=1 to 12 do write(s[i]); write(n);
    end;
    end.

  • 0
    @ 2015-05-23 12:30:22

    注意X这个特殊情况别忘了- -平时写写不注意点没啥事。多交一次。要是比赛就炸了。
    这道题不需要文件读入读出。害我还去写了文件。醉了。

    基础的模拟题。自己按题目意思模拟吧!

    ###pascal code
    program P1484;
    var ISBN,add:string;
    sum,i,s:longint;
    begin //main
    read(ISBN); s:=0;
    for i:=1 to length(ISBN)-1 do
    begin
    if ISBN[i]<>'-' then
    begin
    inc(s);
    sum:=sum+(ord(ISBN[i])-ord('0'))*s;
    end;
    end;
    sum:=sum mod 11; str(sum,add);
    if add='10' then add:='X';
    if add=ISBN[i+1] then
    write('Right')
    else
    begin
    ISBN:=copy(ISBN,1,12); ISBN:=ISBN+add;
    write(ISBN);
    end;
    end.

  • 0
    @ 2015-02-02 18:28:29

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

    }

  • 0
    @ 2014-10-05 11:25:53

    var
    s:string;
    a:array[1..10] of longint;
    i,j,p:longint;
    begin
    readln(s);
    val(s[1],a[1],i);
    val(s[3],a[2],i);
    val(s[4],a[3],i);
    val(s[5],a[4],i);
    val(s[7],a[5],i);
    val(s[8],a[6],i);
    val(s[9],a[7],i);
    val(s[10],a[8],i);
    val(s[11],a[9],i);
    val(s[13],p,i);
    for i:=1 to 10 do
    j:=j+a[i]*i;
    j:=j mod 11;
    if (j=p)or((j=10)and(s[13]='X')) then writeln('Right')
    else
    begin
    for i:=1 to 12 do write(s[i]);
    if j<>10 then writeln(j)
    else writeln('X');
    end;
    end.

  • 0
    @ 2014-10-03 22:52:54

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 552 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 548 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 552 KiB, score = 10
    Accepted, time = 15 ms, mem = 556 KiB, score = 100

    #include<cstdio>
    #include<iostream>
    using namespace std;
    char c;
    int a[11],ver;
    void output(int veri){
    cout<<a[1]<<"-";
    for ( int i= 2;i<=4;i++) cout<<a[i];
    cout<<"-";
    for ( int i=5;i<=9;i++) cout<<a[i];
    if ( veri == 10 ) printf("-X\n");else printf("-%d\n",veri);
    }
    int main()
    {
    c=getchar();
    a[1]=c-'0';
    getchar();
    for ( int i = 2; i <= 4; i++){
    c=getchar();
    a[i]=c - '0';
    }
    getchar();
    for ( int i = 5; i <= 9; i++){
    c=getchar();
    a[i]=c-'0';
    }
    getchar();c=getchar();
    ver = (c == 'X') ? 10 : c - '0';
    int tmp = 0;
    for ( int i=1;i<=9;i++){
    tmp += a[i]*i;
    }
    if ( ver == tmp%11 ) cout<<"Right"<<endl;else output(tmp%11);
    return 0;
    }

  • 0
    @ 2014-08-31 22:56:38

    好水 但是看看自己半年前写的代码 发上来让大家嘲笑一下~! 那时候还小啊~

    #include <cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    char isbn[13];
    int end,tmp;
    int main()
    {
    cin>>isbn;
    end=isbn[0]+2*isbn[2]+3*isbn[3]+4*isbn[4]+5*isbn[6]+6*isbn[7]+7*isbn[8]+8*isbn[9]+9*isbn[10]-45*48;
    tmp=end%11;
    if(tmp==isbn[12]-48)
    cout<<"Right"<<endl;
    else if(tmp==10&&isbn[12]=='X')
    cout<<"Right"<<endl;
    else if(isbn[12]!='X'&&tmp==10)
    cout<<isbn[0]<<isbn[1]<<isbn[2]<<isbn[3]<<isbn[4]<<isbn[5]<<isbn[6]<<isbn[7]<<isbn[8]<<isbn[9]<<isbn[10]<<isbn[11]<<"X";
    else
    cout<<isbn[0]<<isbn[1]<<isbn[2]<<isbn[3]<<isbn[4]<<isbn[5]<<isbn[6]<<isbn[7]<<isbn[8]<<isbn[9]<<isbn[10]<<isbn[11]<<tmp;
    //system("pause");
    return 0;
    }
    //0-670-82162-4

  • 0
    @ 2014-08-22 16:41:45

    超级大水题!!
    #include<iostream>
    #include <cstring>
    #include <cstdlib>

    using namespace std;

    bool func(string &a)
    {
    string ans = a;
    ans.erase(ans.begin() + 1);
    ans.erase(ans.begin() + 4);
    ans.erase(ans.begin() + 9);
    int sum = 0;
    for(int i = 0; i < ans.length() - 1; ++i)
    {
    sum += (ans.c_str()[i] - '0') * (i + 1);
    }
    sum %= 11;
    if(sum == 10 && ans.c_str()[ans.length() - 1] == 'X')
    return true;
    if(sum == ans.c_str()[ans.length() - 1] - '0')
    return true;
    else
    {
    a.erase(a.end() - 1);
    if(sum == 10)
    a += 'X';
    else
    a += sum + '0';
    return false;
    }
    }
    int main()
    {
    string a;
    std::cin>>a;
    if(func(a))
    std::cout<<"Right";
    else
    std::cout<<a;
    return 0;
    }

  • 0
    @ 2014-03-15 10:03:07

    var a,b,i,j:longint; n:int64;
    x:string;
    begin
    read(x);
    j:=0;
    for i:=1 to 11 do
    if (i<>2)and(i<>6) then
    begin
    j:=j+1;
    n:=(ord(x[i])-48)*j+n;
    end;
    a:=n mod 11;
    if (ord(x[13])-48=a) or(ord(x[13])-78=a) then begin writeln('Right'); halt; end
    else begin
    if a=10 then begin for i:=1 to 12 do write(x[i]);write('X') end
    else begin for i:=1 to 12 do write(x[i]);write(a); end; end;
    end.
    要注意大写

  • 0
    @ 2014-03-03 22:35:32

    水翻天的题目,纯模拟就过,全程序没有一个for循环,求虐!
    #include <iostream>
    #include <string>
    #include <cstdio>
    using namespace std;
    string s;
    unsigned int total,i;
    int main(){
    cin>>s;
    total=((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)%11;
    if(total==10)
    {if(s[12]=='X')printf("Right");
    else {s[12]='X';cout<<s;}
    }
    else{
    if((s[12]-'0')==total)printf("Right");
    else {s[12]=total+'0';cout<<s;}
    }
    return 0;
    }

  • 0
    @ 2013-11-29 13:44:54

    #include<cstdio>
    main(){
    int i,j=1,s=0;char a[13];
    for(i=0;i<12;i++){scanf("%c",&a[i]);if(a[i]!='-'){s=s+(a[i]-48)*j;j++;}}
    s=s%11;
    scanf("%c",&a[12]);
    if(s==a[12]-48)printf("Right");
    else if((s==10)&&(a[12]=='X'))printf("Right");
    else{for(i=0;i<12;i++)printf("%c",a[i]);
    if(s==10)printf("X");else printf("%d\n",s);}
    }

信息

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