L1-003 个位数统计
给定一个 k 位整数 N=d
k−1
10
k−1
+⋯+d
1
10
1
+d
0
(0≤d
i
≤9, i=0,⋯,k−1, d
k−1
>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定 N=100311,则有 2 个 0,3 个 1,和 1 个 3。
输入格式:
每个输入包含 1 个测试用例,即一个不超过 1000 位的正整数 N。
输出格式:
对 N 中每一种不同的个位数字,以 D:M 的格式在一行中输出该位数字 D 及其在 N 中出现的次数 M。要求按 D 的升序输出。
输入样例:
100311
输出样例:
0:2
1:3
3:1
n = input()
number = [0] * 10
for i in n:
number[int(i)] += 1
for j in range(10):
if number[j] > 0:
print("{}:{}".format(j, number[j]))
'''n=input()
number=[0]*10
for i in n
number[int9i+=1
for j in
if '''
# from collections import Counter
# s=input()
# b=Counter(s)
# a=[]
# c=[]
#x=dict
#c=dict(b)
#print(c)
#呜呜呜呜,这段代码 格式错误,真真真无语
# for i,j in b.items() :
# a.append(i)
# c.append(j)
# #print(a)
# x=dict(zip(a,c))
# #print(x)
# x1=dict(sorted(x.items(), key=lambda x: x[0]))
# for key,value in x1.items():
# print(key,":",value)
############
# from collections import Counter
# s = input()
# counts = Counter(s)
# for digit in range(10):
# if counts.get(str(digit)):
# print(f'{digit}: {counts[str(digit)]}')