为什么我的 python 代码可以在 Hackerrank、h​​ackerearth 等网站上运行,而在 IDLE 上运行得很好?

Why does my python code does work on sites like Hackerrank, hackerearth etc whereas it works perfectly fine on IDLE?

示例 - 请参阅 https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/roy-and-profile-picture/

处的问题(编码问题)

我的回答如下:

def uploadDP(lines):
    #print(lines)
    l = int(lines[0])
    n = int(lines[1])
    del lines[0]
    del lines[0]
    #print(lines)
    hAr = []
    wAr = []
    for i in range(len(lines)):
        if i%2 == 0:
            hAr.append(int(lines[i]))
        else:
            wAr.append(int(lines[i]))
    #print(hAr,"---",wAr)
    for i in range(len(wAr)):
        #print(i)
        if wAr[i] < l or hAr[i] < l:
            print("UPLOAD ANOTHER")
        elif wAr[i] == l and hAr[i] ==l:
            print("ACCEPTED")
        elif wAr[i] > l or hAr[i] > l:
            print("CROP IT")

lines = []
while True:
    line = input()
    if line:
        lines.append(line)
    else:
        break
uploadDP(lines)

Hackerearth 网站说 - 编译成功,但是没有打印输出。

开始,IDLE,我的代码工作正常。

我认为您需要在本地 运行 并检查您是否正确接受了所有输入。

这是供参考的工作示例代码:

def getoutput():  
    for i in range(val):
        list = []
        line = inputs[i]
        list = line.split(' ')
        if(len(list)<2):
            print('wrong input')
        if list[0] < l or list[1] < l:
            print("UPLOAD ANOTHER")
        elif list[0] == l and list[1] ==l:
            print("ACCEPTED")
        elif list[0] > l or list[1] > l:
            print("CROP IT")



l = input()
line2 = input()
val = int(line2)
inputs = []
for i in range(val):
    line= input()
    inputs.append(line)

getoutput()