0分蒟蒻求助!

P1055 [NOIP2008 普及组] ISBN 号码

Rain888_ @ 2024-07-12 22:36:35

0分蒟蒻求助!

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    int n[10], m, mod, d;
    char ch, c;
    scanf("%d-%d%d%d-%d%d%d%d%d-%c",&n[0],&n[1],&n[2],&n[3],&n[4],&n[5],&n[6],&n[7],&n[8],&ch);
    if (ch == 'X') {
        d = 10;
    }
    else {
        d = ch - 48;
    }
    for (int i = 1; i <= 9; i ++) {
        m += n[i - 1] * i;
    }
    mod = m % 11;
    if (mod == 10) {
        c = 'X';
    }
    else {
        c = mod + 48;
    }
    if (d == mod) {
        cout << "Right" << endl;
    }
    else {
        printf("%d-%d%d%d-%d%d%d%d%d-%c\n",n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],c);
    }
    return 0;
}

by Xuguojian @ 2024-07-13 21:52:20

你这个最显眼的错误就是n数组不能是整数型,还这样的话你输入多个值只会存入一个内容中,以下是更改过后的AC代码

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    char n[9],ch;
    int d,m=0,mod;
    scanf("%c-%c%c%c-%c%c%c%c%c-%c",&n[0],&n[1],&n[2],&n[3],&n[4],&n[5],&n[6],&n[7],&n[8],&ch);
    if (ch == 'X') {
        d = 10;
    }
    else {
        d = ch-'0';
    }
    for (int i = 1; i <= 9; i ++) {
        m += (n[i-1]-'0') * i;
    }
    mod = m % 11;
    if (mod == d) {
        cout << "Right" << endl;
    }
    else {
        if(mod==10){
            printf("%c-%c%c%c-%c%c%c%c%c-X\n",n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8]);
        }
        else{
            printf("%c-%c%c%c-%c%c%c%c%c-%d\n",n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],mod);
        }
    }
    return 0;
}

by Rain888_ @ 2024-07-14 13:23:04

感谢!!!终于AC


|