80分,求助

P1055 [NOIP2008 普及组] ISBN 号码

Noan @ 2023-02-22 16:11:32

#include<stdio.h>
#include<math.h>
int main() {
    char str[13] = { '0' };
    int i = 0;
    for (i = 0; i < 13; i++) {
        scanf("%c", &str[i]);
    }
    int ans = 0, j = 1;
    for (i = 0; i < 12; i++) {
        if (str[i] == '-') {
            ans = ans;
        }
        else {
            ans = ans + (str[i] - '0') * j;
            j++;
        }
    }
    if (str[12] == 'X') {
        if (ans % 11 == 10) {
            printf("Right\n");
        }
        else {
            str[12] = (ans % 11) + '0';
            for (i = 0; i < 13; i++) {
                printf("%c", str[i]);
            }
        }
    }
    if (str[12] != 'X') {

        if (ans % 11 == (str[12]-'0')) {
            printf("Right\n");
        }
        if(ans % 11 != (str[12] - '0')) {
            if (ans % 11 == 10) {
                str[12] = 'X';
            }
            else {
                str[12] = (ans % 11) + '0';
            }
                for (i = 0; i < 13; i++) {
                    printf("%c", str[i]);
                }
            }

    }
    return 0;
}

by Noan @ 2023-02-22 16:30:36

破案了 ,第二个if改成else if


|