py3样例全过但RE 求助

P4414 [COCI2006-2007#2] ABC

qingfengzhihou @ 2024-09-25 19:55:30

代码如下:

dic={'A':0,'B':1,'C':2}
p=0
a=input().split()
a=list(map(int,a))
a.sort()
b=input()
for i in b:
    if p<2:
        print(a[dic[i]],end=' ')
        p+=1
    else:
        print(a[dic[i]])

不能理解。。球球了


by Cstong_y @ 2024-09-25 19:58:42

#include<iostream>
#include<string>
#include<cstring>
using namespace std;

int main()
{
    int A,B,C,temp;
    string s;
    cin>>A>>B>>C;
    cin>>s;
    if(A>B)
    {
        temp = A;
        A = B;
        B = temp;
    }
    if(B>C)
    {
        temp = B;
        B = C;
        C = temp;
    }
    if(A>B)
    {
        temp = A;
        A = B;
        B = temp;
    }
    if(s=="ABC")
    {
        cout<<A<<" "<<B<<" "<<C;
    }
    if(s=="ACB")
    {
        cout<<A<<" "<<C<<" "<<B;
    }
    if(s=="BAC")
    {
        cout<<B<<" "<<A<<" "<<C;
    }
    if(s=="BCA")
    {
        cout<<B<<" "<<C<<" "<<A;
    }
    if(s=="CAB")
    {
        cout<<C<<" "<<A<<" "<<B;
    }
    if(s=="CBA")
    {
        cout<<C<<" "<<B<<" "<<A;
    }
    return 0;
}

@qingfengzhihou


by litangzheng @ 2024-09-25 19:59:32

@Lxzrdg 可是他问的是python3


by qingfengzhihou @ 2024-09-25 20:03:03

@Lxzrdg 啊算法我能理解只是不懂我写的问题在哪里,不过还是感谢:)


by qingfengzhihou @ 2024-09-25 20:09:08

改个输出方式就过了。。这下更不理解了

dic={'A':0,'B':1,'C':2}
p=0
a=list(map(int,input().split()))
list.sort(a)
b=input()
print(a[dic[b[0]]],a[dic[b[1]]],a[dic[b[2]]])

:(


by heyongheng_20242782 @ 2024-10-04 20:03:02

@qingfengzhihou 好像它的测试用例有问题,它的输入不只是“ABC”,后面还有东西,所以你第一次代码for i in b就弄到了后面的某种东西上,而第二次代码你没有涉及到后面的某种东西上,所以过了


by qingfengzhihou @ 2024-10-12 13:10:39

@gousheng123 啊哈 原来如此,感谢解惑


|