求助,#5,6,9WA,70分

P1055 [NOIP2008 普及组] ISBN 号码

GuiyuanCo @ 2023-09-14 21:33:28

#include <iostream>
using namespace std;
int main()
{
    string s,t="0123456789X";
    int a=0,j=1;
    cin>>s;
    for (int i=0;i<=s.size()-2;i++)
    {
        if (s[i]=='-')
        {
            continue;
        }
        if (s[i]>='0'&&s[i]<='9')
        {
            a+=(s[i]-'0')*(j++);
        }
    }
    if (t[a%11]==s[s.size()-1]) cout<<"Right";
    else if (a%11!=10) {s[s.size()-1]=t[a%11];cout<<s;}
}

by liu_le_chen @ 2023-09-14 21:35:14

@xieyuanxi 不难,可以自己理解一下

#include<bits/stdc++.h>
using namespace std;
string s;
long long cnt,v;
int main(){
    cin>>s;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]>='0' && s[i]<='9'){
            v++;
            cnt+=(s[i]-'0')*v;
        }
    }
    if(cnt%11==s[s.length()-1]-'0' || (cnt%11==10 && s[s.length()-1]=='X')) cout<<"Right";
    else{
        for(int i=0;i<s.length()-1;i++){
            cout<<s[i];
        }
        if(cnt%11==10){
            cout<<'X';
            return 0;
        }
        cout<<cnt%11;
    }
    return 0;
}

求关!!!


by Emplace @ 2023-09-14 21:51:19

接楼上,确实。

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

int main() {
    char s[20];
    cin >> s;
    int len = strlen(s), cnt = 0, k = 1;
    for (int i = 0; i < len - 2; i++) {
        if (s[i] != '-') {
            cnt += k * (s[i] - '0');
            k++;
        }
    }
    cnt %= 11;
    char c = cnt + '0';
    if (cnt == 10) {
        c = 'X';
    }
    if (s[len - 1] == c) {
        cout << "Right";
    } else {
        s[len - 1] = 0;
        cout << s;
        cout << c;
    }
    return 0;
}

by GuiyuanCo @ 2023-09-14 21:52:50

ok,把条件判断改了ac了,wssb


by rrrstj @ 2024-04-14 02:06:16

@GuiyuanCo 可以问一下是什么条件吗 aaaa还是过不去不知道为什么


by rrrstj @ 2024-04-14 02:08:59

@GuiyuanCo ```cpp


#include<iostream>
#include<cstring>
using namespace std;

int main(){
    string c;
    cin>>c;
    int len = c.length();
    int count = 0;
    int j = 1;
    for(int i = 0; i < len-2; i++){
        if(c[i] == '-'){
            continue;
        }
        else {
            count += (c[i] - '0')*j;
            j++;
        }
    }
    count = count%11;
    if((c[len-1] == 'X' && count == 10)){
        cout<<"Right"<<endl;
    }
    else if(c[len-1]-'0'== count) {
        cout<<"Right"<<endl;
    }
    else if(count == 10){
        c[len-1] = 'X';
    }
    else {
        c[len-1] = count +'0';
        cout<<c<<endl;
    }
    return 0;
}

|