为什么一直错? QWQ~

P1055 [NOIP2008 普及组] ISBN 号码

Zhouyuhan_1125 @ 2022-07-29 18:39:06

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

int main(){
    string a;
    int ch = 1,sum = 0;
    cin >> a;
    for(int i = 0; i < a.size(); i++){
        if(a[i] != '-'){
            sum += a[i] * ch;
            ch++;
        }
    }
    for(int i = 0; i < a.size(); i++){
        if(sum % 11 == a[a.size() - 1]){
            cout << "Right" << endl;
            return 0;
        } else {
            a[a.size() - 1] = sum % 11;
            for(int j = 0; j < a.size(); j++){
                cout << a[i];
            }
        }
    }
    return 0;
}

by zlttcl @ 2022-07-29 18:45:26

既然只判断最后一个数字为什么还要for循环一遍


by zlttcl @ 2022-07-29 19:02:52


by zlttcl @ 2022-07-29 19:06:08


|