CCF考试试题之门禁系统java解题代码
作者:zjj582984208 时间:2022-10-05 02:39:27
问题描述
涛涛最近要负责图书馆的管理工作,需要记录下每天读者的到访情况。每位读者有一个编号,每条记录用读者的编号来表示。给出读者的来访记录,请问每一条记录中的读者是第几次出现。
输入格式
输入的第一行包含一个整数n,表示涛涛的记录条数。
第二行包含n个整数,依次表示涛涛的记录中每位读者的编号。
输出格式
输出一行,包含n个整数,由空格分隔,依次表示每条记录中的读者编号是第几次出现。
样例输入
5
1 2 1 1 3
样例输出
1 1 2 3 1
评测用例规模与约定
1≤n≤1,000,读者的编号为不超过n的正整数。
解题代码(java):
方法一:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int N=scanner.nextInt();
int[] arr=new int[N];
int[] arr1=new int[N];
arr1[0]=1;
for(int i=0;i<N;i++){
arr[i]=scanner.nextInt();
}
for(int i=1;i<N;i++){
int count=1;
for(int j=i-1;j>=0;j--){
if((arr[j])!=(arr[i])){
arr1[i]=count;
}else{
count++;
arr1[i]=count;
}
}
}
for(int i=0;i<N;i++){
System.out.print(arr1[i]+" ");
}
}
}
方法二:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int[]arr=new int[n];
for(int i=0;i<arr.length;i++){
arr[i]=scanner.nextInt();
}
for(int i=0;i<arr.length;i++){
int count=1;
for(int j=i-1;j>=0;j--){
if(arr[j]==arr[i]){
count++;
}
}
System.out.print(count+" ");
}
}
}
来源:https://blog.csdn.net/zjj582984208/article/details/55212571
标签:java,CCF,门禁系统
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringBoot构建ORM框架的方法步骤
2023-10-31 20:41:21
![](https://img.aspxhome.com/file/2023/3/58543_0s.png)
Java 逻辑运算符中&&与&,||与|的区别
2021-05-30 15:24:26
C#调用WebService的方法介绍
2022-06-05 01:10:30
![](https://img.aspxhome.com/file/2023/0/89850_0s.jpg)
java生成excel报表文件示例
2023-02-27 13:17:49
WebView的介绍与简单实现Android和H5互调的方法
2023-04-30 19:26:00
![](https://img.aspxhome.com/file/2023/7/101817_0s.png)
java虚拟机学习笔记进阶篇
2022-01-07 04:53:06
![](https://img.aspxhome.com/file/2023/9/69109_0s.png)
SprintBoot深入浅出讲解场景启动器Starter
2023-11-24 20:58:58
![](https://img.aspxhome.com/file/2023/9/59419_0s.png)
C#实现根据指定容器和控件名字获得控件的方法
2023-09-26 12:23:03
JAVA与SQL 中的null与NULL解析
2023-06-23 11:51:18
![](https://img.aspxhome.com/file/2023/0/72380_0s.png)
深入分析C# Task
2022-10-24 12:39:00
Java多线程ForkJoinPool实例详解
2022-03-15 17:05:13
idea项目的左侧目录没了如何设置
2022-03-21 15:45:43
![](https://img.aspxhome.com/file/2023/1/86801_0s.jpg)
PyQt5内嵌浏览器注入JavaScript脚本实现自动化操作的代码实例
2023-11-26 15:05:59
Android 配置gradle实现VersionCode自增实例
2021-07-03 12:39:23
![](https://img.aspxhome.com/file/2023/8/101848_0s.jpg)
MyBatis测试报错:Cannot determine value type from string 'xxx'的解决办法
2023-03-26 07:19:46
Java8使用stream实现list中对象属性的合并(去重并求和)
2023-06-23 13:44:40
![](https://img.aspxhome.com/file/2023/9/62379_0s.png)
基于Java8实现提高Excel读写效率
2023-11-25 10:01:37
盘点MQ中的异常测试
2022-05-06 07:39:24
Java 中HashCode作用_动力节点Java学院整理
2021-12-08 12:26:55
![](https://img.aspxhome.com/file/2023/1/96821_0s.png)
java实现二叉树的创建及5种遍历方法(总结)
2022-03-14 09:00:28