0分求调

P1055 [NOIP2008 普及组] ISBN 号码

xuanmangguo @ 2024-08-09 09:56:47

#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int sum=0,chengshu=1,f=0;
    for(int i=0;i<s.length();i++) {
        if(s[i]!='-') {
            sum+=(s[i]-'0')*chengshu;
            chengshu++;
        }
    }
    sum%=11;
    if(sum==s[s.length()-1]) {cout<<"Right";f=1;}
    if(!f) {
        s[s.length()-1]=char(sum+48);
        for(int i=0;i<s.length();i++) cout<<s[i];
    }
    return 0;
}

by Greeper @ 2024-08-09 09:58:15

@xuanmangguo 可以用int变量 求关注谢谢

#include<iostream>
using namespace std;
int main()
{
    int a,b,c,e;
    char x,y,z,d;
    cin>>a>>x>>b>>y>>c>>z>>d;
    if(d!='X')
    {
        e=int(d-'0');
    }
    else
    {
        e=10;
    }
    int m=a*100000000+b*100000+c;
    int id=0;
    int i=9;
    while(i)
    {
        id+=m%10*i;
        m/=10;
        i--;
    }
    if(id%11==e)
    {
        cout<<"Right";
    }
    else
    {
        cout<<a<<'-'<<b<<'-'<<c<<'-';
        if(id%11==10)
        {
            cout<<'X';
        }
        else
        {
            cout<<id%11;
        }
    }
    return 0;
}

by caozhihan @ 2024-08-09 10:34:42

别搞那么复杂,多写几行代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int rt;
    cin>>str;
    rt=int((str[0]-'0')*1+(str[2]-'0')*2+(str[3]-'0')*3+(str[4]-'0')*4+(str[6]-'0')*5+(str[7]-'0')*6+(str[8]-'0')*7+(str[9]-'0')*8+(str[10]-'0')*9);
    rt%=11;
    if((int(str[12]-'0')==rt)||(rt==10&&str[12]=='X'))
    {
        cout<<"Right";
    }
    else
    {
        for(int i=0;i<=11;i++)
        {
            cout<<str[i];
        }
        if(rt==10) cout<<'X';
        else cout<<rt; 
    }
    return 0;
}

by LEZ2012 @ 2024-08-09 21:16:58


#include<ios>
#include<cstring>
using namespace std;
char s[21];
int main(){
    scanf("%s",s+1);
    int n=13,m=0,x=0;
    for(int i=1;i<n;i++)
    if(s[i]!='-'){
        int y=s[i]-'0';
        x++;
        m+=x*y;
    }
    m%=11;
    char c;
    if(m==10)
    c='X';
    else
    c=m+'0';
    if(s[n]==c)
    printf("Right");
    else{
        for(int i=1;i<n;i++)
        printf("%c",s[i]);
        printf("%c",c);
    } 
}

by LEZ2012 @ 2024-08-09 21:17:29

求互关


|