救救孩子吧 求大神看看问题在哪里 一上午了没做出来这道题

P1055 [NOIP2008 普及组] ISBN 号码

are_trying_coding @ 2021-11-21 10:41:35

#include<iostream>
#include<string>
using namespace std;
int main()
{
    int sum,j=1;
    string s1;
    cin>>s1;
    for(int i=0;i<s1.size()-2;i++)
    {
        if(s1[i]!='-')
        {
            sum+=(s1[i]-'0')*j;
            j++;
        }
     } 
     sum%=11;

     if(sum==10)
     {
        if(s1[s1.size()-1]=='X')
        cout<<"Right";
        else
        {
            for(int i=0;i<s1.size()-1;i++)
                cout<<s1[i];
            cout<<"X";

         }
        return 0;
     }
    if((s1[s1.size()-1]-'0')==sum)
        cout<<"Right";

    else
        {
            for(int i=0;i<s1.size()-1;i++)
                cout<<s1[i];
            cout<<sum;

         }
     return 0;
}

by are_trying_coding @ 2021-11-21 10:42:25

在线求教


|