package CSP;
import java.util.Scanner;
import java.util.Vector;
public class Main {
public static int Printcount(Vector<Integer> vec,int num) {
int count=0;
for(int i:vec) {
if(i==num) count++;
}
return count;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int num=0;
num = Integer.parseInt(s.nextLine());
String[] str = s.nextLine().split(" ");
//总的数字的vector
Vector<Integer> vec = new Vector<Integer>();
//不重复数字的vector
Vector<Integer> vec1 = new Vector<Integer>();
for(String i:str) {
int j = Integer.parseInt(i);
vec.addElement(j);
if(!vec1.contains(j)) {
vec1.addElement(j);
}
}
//出现次数最多的数字
int ans=0;
//该数字出现的次数
int count=0;
for(int i:vec1) {
int temp = Printcount(vec,i);
if(temp>count) {
ans=i;
count=temp;
}else if (temp==count && i<ans) {
ans=i;
count=temp;
}
}
System.out.println(ans);
}
}
CCF-CSP 201312-1出现次数最多的数
最新推荐文章于 2023-03-10 11:57:18 发布