CSP201412-1: Access Control System, csp201412-1
Introduction:CSPHttp://www.cspro.org/lead/application/ccf/login.jsp)YesbyChina Computer Society (CCFThe "Computer vocational qualification certification" examination is initiated to authenticate the competence of professionals in computer software development, software testing, information management, and other fields. The authenticated object is engaged in or will be engaged inITSpecialized technical and technical management personnel in the field, as well as review objects for university candidates.
LProblem description
Tao is responsible for the management of the library recently and needs to record the visits of readers every day. Each reader has a number. Each record is represented by the number of the reader. The reader's access record is provided. Which of the following is the first appearance of each record.
LInput Format
The first line of the input contains an integer n, indicating the number of records of Tao.
The second line contains n integers, which represent the numbers of each reader in Tao's records in turn.
LOutput Format
The output line contains n integers separated by spaces, indicating the number of readers in each record in sequence.
LSample Input
5
1 2 1 3
LSample output
1 1 2 3 1
LScale and conventions of evaluation cases
1 ≤ n ≤ 1,000, the reader number is a positive integer not greater than n.
LSource 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 else41 {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 else56 {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}