(算法练习)——201412-1门禁系统(CCF模拟)

这一题一开始理解错了题意,对于每个读者的编号并非是从1开始顺序的,也就是说,可能会出现这样的输入数据:
5
1 1 100 2 3
一开始还用了两个数组、set,提交只有40分= =
重写了一遍,只用两个数组,配合着表示就可以了(其实这一题一个数组肯定也是可以的)
AC代码:

#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    
    
	int n;
	int ans[1010];
	int num[1010];
	for(int i = 0;i <1010;i++){
    
    
		ans[i] = 0;
		num[i] = 0;
	}
	int number;
	scanf("%d",&n);
	for(int i = 0;i <n;i++){
    
    
		scanf("%d",&number);
		num[i] = ++ans[number];   //先++再取值 
	}
	for(int i = 0;i <n;i++){
    
    
		printf("%d ",num[i]);
	}
	
}

猜你喜欢

转载自blog.csdn.net/weixin_42377217/article/details/104546305