7-6 Statistics seniority (20 points)

7-6 Statistics seniority (20 points)

Length of service given to employees of the company N, in increasing order of length of service required by the output of each segment length of service the number of employees.

Input formats:

Firstly, the input integer \ (N (≦ 10 ^. 5) \) , i.e., the total number of employees; N integers given later, i.e., length of service of each employee, in the range [0, 50].

Output formats:

The number of employees for each output seniority ascending order of seniority, the format is: "length of service: Number." Each separate line. If the number is 0 is not output.

Sample input:

8
10 2 0 5 7 2 5 2

Sample output:

0:1
2:3
5:2
7:1
10:1
n = int(input())
out = {}
data = list(map(int, input().split()))
for item in data:
    out[item] = out.get(item, 0) + 1

for item in sorted(out.keys()):
    print(f"{item}:{out[item]}")

Guess you like

Origin www.cnblogs.com/nobilis/p/11878872.html