输入一系列以空格分隔的1-100的数字,对出现的数字计数。按数字由小到大显示。示例如下:
1 occurs 2 times
2 occurs 2 times
3 occurs 2 times
100 occurs 1 time
import collections def main(): # ls = [int(i) for i in input().split()] ls = [111,100,11,11,3,2,1,3,2] ls.sort() b = collections.Counter(ls) for c in b: if b[c] == 1: print(c, "occurs", b[c], "time") else: print(c, "occurs", b[c], "times") main()
运行一下,结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)