CCF-CSP 201412-1 access control system

Problem description
  Tao Tao has recently been responsible for the management of the library, and needs to record the daily visits of readers. Each reader has a number, and each record is represented by the reader's number. Given the visit records of readers, how many times does the reader appear in each record.
Input format
  The first line of input contains an integer n, which indicates the number of Taotao records.
  The second line contains n integers, which in turn represent the number of each reader in Tao Tao's record.
Output format
  Output a line, containing n integers, separated by spaces, which means that the reader number in each record is the first occurrence.
Sample input
5
1 2 1 1 3
Sample output
1 1 2 3 1
Evaluation use case scale and convention 1
  ≤ n ≤ 1,000, the reader's number is a positive integer not exceeding n.

Summary of experience:
Use array subscripts to mark the number of times the reader number appears.

C ++ code:

#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,a;
	scanf("%d",&n);
	int num[n+1]= {0};
	scanf("%d",&a);
	num[a]++;
	printf("%d",num[a]);
	for(int i=1; i<n; i++) {
		scanf("%d",&a);
		num[a]++;
		printf(" %d",num[a]);
	}
	return 0;
}
Published 111 original articles · won praise 2 · Views 3533

Guess you like

Origin blog.csdn.net/m0_38088647/article/details/100513281