读取行或id时的EOF

2024-04-25 22:00:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是在做一个程序,做以下事情

  1. 你输入某物的“计数”
  2. 然后为每个由空格分隔的“计数”输入一个值
  3. 您将得到输出:其中有多少个是重复的,哪个重复的数字是最高的,再次用空格分隔

基本上: 输入:

8           
12 12 16 102 47 16 102 47

输出:

4 102

问题是我的代码没有一个点,我也不知道问题出在哪里。 In在我的python中工作,但在某些在线编译器中不工作,因此接收者可能会遇到与在线站点相同的程序问题

def thing():
    global count
    count = int(input('n:'))
    if count > 100000:
        exit()
    elif count < 1:
        exit()
    else:
        wut()
def wut():
    idk = []
    inp = list(map(int,input('ai:').split(' ')))
    if len(inp) != count:
        exit()
    elif sum(inp) > 200000:
        exit()
    elif sum(inp) < 1:
        exit()
    else:
        for i in range(len(inp)):
            for x in range(i+1, len(inp)): 
                if inp[i] == inp[x]:
                    idk.append(inp[i])
    o = len(idk)
    idk.sort(reverse = True)
    print(o, idk[0])

thing()

在我的Python3.7.4中,它工作得很好,但我没有得到任何一点


Tags: 程序inputlenifdefcountexitelse
1条回答
网友
1楼 · 发布于 2024-04-25 22:00:01
from collections import Counter

# Convert them all to an int
numbers = [int(i) for i in input("Numbers: ").split(" ")]

# Get number of input
count = len(numbers)

counter = Counter(numbers)

# Get the highest value of the most common values
max_dup, _ = max(counter.most_common(), key=lambda ele: ele[0])

# Get the amount of duplicates
dups = len(list(filter(lambda k: k[1] > 1, counter.items())))

print(dups, end=" ")

print(max_dup)

collections.Counterfilter

相关问题 更多 >

    热门问题