我不确定这个问题是怎么回事。
我将完全相同的代码放在Jupyter笔记本中,一切运行良好。但是当我将代码放在 Hackerrank 中时,它不会返回任何输出。
有人在这里发现错误吗?
样本:
6 4
今天晚上给我一个盛大的夜晚
今天给一个盛大
#!/bin/python3
import math
import os
import random
import re
import sys
from collections import Counter
# Complete the checkMagazine function below.
def checkMagazine(magazine, note):
ds = Counter(magazine)
for m in note:
ds[m] = ds[m] - 1
if ds[m] < 0 or ds[m] is None: return 'No'
return 'Yes'
if __name__ == '__main__':
mn = input().split()
m = int(mn[0])
n = int(mn[1])
magazine = input().rstrip().split()
note = input().rstrip().split()
checkMagazine(magazine, note)
此代码return
s,但不print
HR 代码运行程序正在查找的 stdout 输出。试试print(checkMagazine(magazine, note))
.
总的来说,HR对IO有点挑剔。数据将通过 stdin 读取并打印到 stdout,通常以奇怪的格式(如"Yes"
或"Impossible!"
表示通常返回布尔值的函数。