python问题,难倒同学无数_(:з」∠)_
其他问答
1
问题遇到的现象和发生背景 题目要求: 输入 5(输入的个数) 1 10 (1-10) 7 9 3 8 4 7 (4-7) 5 5 (5:5 只有5) 输出 1 1 (1、计算1出现的次数) 2 1(2、2出现的次数,为1) 3 2(3、3出现的次数,为2) 4 3 5 4 6 3 7 3 8 3 9 2 10 1
问题相关代码
a=int(input())
c = [[],[]]
for i in range(a):
b = [int(n) for n in input().split()]
c[0].append(b[0])
c[1].append(b[1])
for i in range(min(c[0]),max(c[1])+1):
m = len([n for n in c[0] if n<=i])
n = len([n for n in c[1] if n<i])
if m-n>0:
print(i,m-n)
-
def BinarySearch(li,n,k): if k<li[0]: return 0 if k>=li[-1]: return n left=0 right=n-1 while left<=right: middle=(left+right)//2 if li[middle]<=k: left=middle+1 if li[middle]>k: right=middle-1 return left; n = int(input()) li1 = [] li2 = [] for i in range(n): a,b = map(int,input().split()) li1.append(a) li2.append(b) li1.sort() li2.sort() for i in range(li1[0],li2[-1]+1): a = BinarySearch(li1,n,i) b = BinarySearch(li2,n,i-1) m = a-b if m>0: print(i,m)
-
a=int(input()) c = [] for i in range(a): x,y=[int(n) for n in input().split()] c += range(x,y+1) for i in range(min(c),max(c)+1): m = c.count(i) if m>0: print('{} {}'.format(i,m))
发表回复