JAVA CCF-201412-1 门禁系统

欢迎访问我的CCF认证解题目录


题目描述

在这里插入图片描述


思路过程

题目的意思就是求当前的数字第几次出现,而且这个数不会超过n,那么我们可以定义一个数组来记录出现的次数(对应的下标就是出现的次数)


代码

这应该是我解过的最短代码了吧。。。

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] cnt = new int[n+5];
		while ( n-- != 0 ) System.out.print(++cnt[in.nextInt()]+" ");
	}
	
}
发布了60 篇原创文章 · 获赞 0 · 访问量 2142

猜你喜欢

转载自blog.csdn.net/weixin_43732798/article/details/103374312