CCF之小明上学——2018.12 第一题 (java满分代码)
作者:互联网
package Question_one;
/*
* 出现次数最多的数
*/
import java.util.*;
public class Question_2013_12 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int []arry = new int[N];
int []count = new int[N];
for(int i = 0;i <N;i++) {
arry[i] = scanner.nextInt();
count[i]=1;
}
for(int i = 0;i<N;i++) {
for(int j = i+1; j <N;j++) {
if(arry[j] == arry[i])
count[i]++;
}
}
int max=0;
int p = 0 ;
int m;
for(int i = 0 ;i <N;i++) {
if(count[i]>max) {
max = count[i];
p = i;
}else if(count[i] == max) {
if(arry[p]>arry[i])
p=i;
}
}
System.out.println(arry[p]);
}
}
不足之处,欢迎指正!
标签:count,java,scanner,之小明,int,max,2018.12,new,arry 来源: https://blog.csdn.net/Ruky_Z/article/details/88371683