80分求助!!!大佬帮帮我

P1055 [NOIP2008 普及组] ISBN 号码

A_chicken_boy @ 2022-11-19 15:51:01


#include <bits/stdc++.h>
using namespace std;
string s;
int sum ;
int main ()
{
    getline ( cin , s ) ;
    int l = s.size () ;
    if ( l != 13){
        for ( int i = 0 ; i <= 12 ; ++i )
        {
            cout << s[i] ;
        }
        return 0;
    }
        sum += (s[0] - '0') * 1 ;
        sum += (s[2] - '0') * 2 ;
        sum += (s[3] - '0') * 3 ;
        sum += (s[4] - '0') * 4 ;
        sum += (s[6] - '0') * 5 ;
        sum += (s[7] - '0') * 6 ;
        sum += (s[8] - '0') * 7 ;
        sum += (s[9] - '0') * 8 ;
        sum += (s[10] - '0') * 9 ;
        sum %= 11 ;
    if ( sum == 10 && s[12] == 'X' ){
        cout << "Right" ;
    }else if ( sum == s[12] - '0' )
    {
        cout << "Right" ; 
    }else
    {
        for ( int i = 0 ; i <= 11 ; ++i )
        {
            cout << s[i] ;
        }
        if ( sum == 10 )
        {
            cout << "X" ;
        }else 
        {
            cout << sum ;
        }
    }
    return 0; 
}

by wuyuchen5001143 @ 2023-01-05 21:47:33

和我一模一样,数据末尾有空格,所以getline()会多读一个空格,现已修复,你再提交一遍就行了


by A_chicken_boy @ 2023-01-18 11:28:13

thanks for your help !


|