import java.util.Scanner; public class Test { public static void main(String[] args) { int length; int idnum[]={0,0,0}; int ID[]={0,0,0}; System.out.println("请输入总帖子数量:"); Scanner in=new Scanner(System.in); length=in.nextInt(); int curId[]=new int[length]; System.out.println("请输入所有帖子的ID列表"); for(int j=0;j<length;j++) { curId[j]=in.nextInt(); } for(int i=0;i<length;i++) { if(idnum[0]==0&&curId[i]!=ID[1]&&curId[i]!=ID[2]) { idnum[0]=1; ID[0]=curId[i]; } else if(idnum[1]==0 && curId[i]!=ID[0] && curId[i]!=ID[2]) { idnum[1]=1; ID[1]=curId[i]; } else if(idnum[2]==0 && curId[i]!=ID[0] && curId[i]!=ID[1]) { idnum[2]=1; ID[2]=curId[i]; } else if(curId[i]!=ID[0] && curId[i]!=ID[1] && curId[i]!=ID[2]) { idnum[0]--; idnum[1]--; idnum[2]--; } else if(curId[i]==ID[0]) { idnum[0]++; } else if(curId[i]==ID[1]) { idnum[1]++; } else if(curId[i]==ID[2]) { idnum[2]++; } } System.out.println("发帖最多的三个人ID为:"+ID[0]+" "+ID[1]+" "+ID[2]); } }
结果截图: