Chapter 5-6. Statistical seniority (20 points)

Given the company seniority N employees, in increasing order of length of service required by the output of each segment length of service the number of employees.

Input formats:

Firstly, input a positive integer N ( ≤), i.e., the total number of employees; subsequently given N integers, 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
 1 # 统计工龄
 2 # Author: cnRick
 3 # Time  : 2020-4-3
 4 n = int(input())
 5 result = {}
 6 ages = list(map(int,input().split()))
 7 for i in range(n):
 8     result[ages[i]] = result.get(ages[i],0) + 1
 9 keys = list(result.keys())
10 keys.sort()
11 for i in range(len(keys)):
12     print("{:d}:{:d}".format(keys[i],result[keys[i]]))

 

 

Guess you like

Origin www.cnblogs.com/dreamcoding/p/12625751.html