30分蒟蒻求救

P1055 [NOIP2008 普及组] ISBN 号码

HaloCode @ 2024-03-17 10:30:02

求救

用这个代码可以30分(但是我觉得第一个数字应该乘1):

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int cnt = 2, he = 0, zong = 0, shibiema;
    string isbn;
    getline(cin, isbn);
    he = isbn.at(0) * 0;
    for(int i = 2; i <= 4; i++){
        he = isbn.at(i) * cnt;
        zong += he;
        cnt++;
    }
    for(int i = 6; i <= 10; i++){
        he = isbn.at(i) * cnt;
        zong += he;
        cnt++;
    }

    shibiema = zong % 11;
    char a;
    a = shibiema + '0';
    if(a == isbn.at(12)){
        cout << "Right";
    }else{
        isbn.at(12) = a;
        cout << isbn;
    }
    return 0;
}

写完上面的代码后我发现第一个数字应该是乘1而不是0,可是如果让第一个数字乘1而不是乘0,就会0分:

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int cnt = 2, he = 0, zong = 0, shibiema;
    string isbn;
    getline(cin, isbn);
    he = isbn.at(0) * 1;
    for(int i = 2; i <= 4; i++){
        he = isbn.at(i) * cnt;
        zong += he;
        cnt++;
    }
    for(int i = 6; i <= 10; i++){
        he = isbn.at(i) * cnt;
        zong += he;
        cnt++;
    }

    shibiema = zong % 11;
    char a;
    a = shibiema + '0';
    if(a == isbn.at(12)){
        cout << "Right";
    }else{
        isbn.at(12) = a;
        cout << isbn;
    }
    return 0;
}

|