Introduction: CSP (http://www.cspro.org/lead/application/ccf/login.jsp) It is a "computer professional qualification certification" examination initiated by China Computer Society (CCF), aiming at the ability certification of professionals in computer software development, software testing, information management and other fields. Certification object is engaged in or will be engaged in the IT field of professional technology and technical management personnel, as well as the re examination object of postgraduate enrollment in Colleges and universities.
l. problem description
Taotao is in charge of the management of the library recently. He needs to record the visit of readers every day. Each reader has a number, and each record is represented by the reader's number. Give the visiting records of the readers. How many times do the readers appear in each record.
l input format
The first line of input contains an integer n, indicating the number of records of Taotao.
The second line contains n integers, which in turn represent the number of each reader in Taotao's record.
l output format
The output line contains n integers, separated by spaces, indicating the number of readers in each record in turn.
l sample input
5
1 2 1 1 3
l sample output
1 1 2 3 1
l. scale and agreement of evaluation case
1 ≤ n ≤ 1000, the reader's number is a positive integer not more than n.
l. source code
1 # include <stdio.h> 2 # include <stdlib.h> 3 # include <memory.h> 4 5 struct MyData { 6 int key; 7 int value; 8 }; 9 10 int main(void) 11 { 12 int n; //Number 13 int flag = 1; 14 int count = 0; 15 scanf("%d", &n); 16 17 int *input = (int *)malloc(sizeof(int) * n); 18 memset(input, 0, sizeof(int) * n); 19 struct MyData *temp = (struct MyData *)malloc(sizeof(struct MyData) * n); 20 memset(temp, 0, sizeof(struct MyData) * n); 21 22 for (int i = 0; i < n; i++) 23 { 24 scanf("%d", input+i); 25 } 26 27 for (int i = 0; i < n; i++) 28 { 29 for (int j = 0; j < count; j++) 30 { 31 if (input[i] == temp[j].key) 32 { 33 temp[j].value += 1; 34 count += 1; 35 flag = 0; 36 if (i == n-1) 37 { 38 printf("%d\n", temp[j].value); 39 } 40 else 41 { 42 printf("%d ", temp[j].value); 43 } 44 break; 45 } 46 } 47 if (flag) 48 { 49 temp[count].key = input[i]; 50 temp[count].value = 1; 51 if (i == n-1) 52 { 53 printf("%d\n", temp[count].value); 54 } 55 else 56 { 57 printf("%d ", temp[count].value); 58 } 59 count += 1; 60 } 61 flag = 1; 62 } 63 64 free(input); 65 free(temp); 66 67 return 0; 68 }