py3求助 #4实在不知道为啥错了,我也没权限下载测试点

P1055 [NOIP2008 普及组] ISBN 号码

Trainer_Marvin @ 2022-11-29 23:55:12

P1055

origin = input().split('-')

num = ''.join(origin[0:3])

def n(i):

x = 0
for t in range(0, len(i)):
    x += int(i[t]) * (t + 1)
x = x % 11
if x == 10:
    x = 'X'
return str(x)

m = n(num)

if m == origin[-1]:

print('Right')

else:

origin[-1] = m
print('-'.join(origin))

by LeTu_Jun @ 2022-11-30 07:18:46

希丰展使md


by ISTP @ 2022-11-30 07:34:34

@Trainer_Marvin 您的 Markdown 又炸了 ()


by 杨建韬 @ 2022-11-30 09:03:18

还是这样好看:

origin = input().split('-')

num = ''.join(origin[0:3])

def n(i):

x = 0
for t in range(0, len(i)):
    x += int(i[t]) * (t + 1)
x = x % 11
if x == 10:
    x = 'X'
return str(x)
m = n(num)

if m == origin[-1]:

print('Right')
else:

origin[-1] = m
print('-'.join(origin))

by 杨建韬 @ 2022-11-30 09:03:38

虽然没缩进了


by Trainer_Marvin @ 2022-11-30 16:58:12

@QiMi 还不太会用,抱歉


by ISTP @ 2022-11-30 18:12:03

@杨建韬 没缩进的 py 不就废了吗......

python 是我们学校必修,但我更擅长 c++ ,你程序上有的函数我都看不懂


by ISTP @ 2022-11-30 18:28:16

@Trainer_Marvin 如果你看得懂 C++ ,这里有个简单暴躁的代码:

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

by 杨建韬 @ 2022-11-30 18:31:24

origin = input().split('-')
num = ''.join(origin[0:3])
def n(i):
    x = 0
    for t in range(0, len(i)):
        x += int(i[t]) * (t + 1)
    x = x % 11
    if x == 10:
        x = 'X'
    return str(x)
m = n(num)
if m == origin[-1]:
    print('Right')
else:
    origin[-1] = m
    print('-'.join(origin))

by Trainer_Marvin @ 2022-11-30 19:21:51

@杨建韬 那么我的算法哪里有错啊


by 杨建韬 @ 2022-11-30 21:42:08

en ...第四组数据是:

6-670-82162-X

你的代码会直接输出这一行,其实答案是“Right”


| 下一页