import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
public class Shuzu
{
public static void main(String args[])
{
//标准输入
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=null;
String ch=null;
int []a=new int[1024];
try {
str=br.readLine();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int j=0;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)!=',')
{
ch=Character.toString(str.charAt(i));
a[j]=Integer.parseInt(ch);
System.out.println(a[j]);
j++;
}
}
Map map=new HashMap();
for(int i=0;i<j;i++)
{
if(map.containsKey(a[i]))
{
map.put(a[i],((Integer)map.get(a[i])).intValue()+1);
}
if(!map.containsKey(a[i]))
{
map.put(a[i], 1);
}
}
Set set=map.entrySet();
Iterator ite=set.iterator();
while(ite.hasNext())
{
Map.Entry<Integer, Integer> me=(Map.Entry<Integer, Integer>)ite.next();
if(me.getValue()>=j/2)
{
System.out.println("输入的数组中支配者为: "+me.getKey()+" 共出现"+me.getValue()+"次");
}
}
}
}
输入一组整型数据,以逗号隔开,寻找出现次数大于总数一半的数
最新推荐文章于 2021-07-20 18:58:13 发布