Given the company N seniority 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 (≤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
First, step
Using an array of size 50, initialized to 0, as the length of service array index size, length of service when a read, the array corresponding to the value +1 in target position, and finally through the array, the array output is not zero.
Second, the code
#include<stdio.h>
#include<stdlib.h>
int main ()
{
int i, x, n;
scanf("%d", &n);
int s[51] = {0};
for(i = 0; i < n; i ++) {
scanf("%d", &x);
s[x] ++;
}
for(i = 0; i <= 50; i ++) {
if(s[i]) {
printf("%d:%d\n", i, s[i]);
}
}
return 0;
}