Design ideas:
Defines the array storage ID. Each water King ID is offset from the other Navy ID. First three different Navy ID is set to the Water King ID, start to offset the count, "Water king" in the amount of the remaining 0 is eliminated, with a new Navy ID to continue to cancel, the last remaining is the water King ID.
Source:
Import Java.util.scanner;public class Main {public static void main (string[] args) {//TODO auto-generated method Stubint length;//number of posts int idnum[]={0,0,0};//count int id[]={0,0,0};//storage Water King address System.out.println ("Please enter the total number of posts:"); Scanner in=new Scanner (system.in); Length=in.nextint (); int Curid[]=new int[length];//stores all ID addresses System.out.println ("Please enter the ID list of the Navy"); for (int j=0;j<length;j++) {curid[j]=in.nextint (); }/* Solution process */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] &&Amp 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 ("Three Water king ID:" +id[0]+ "" +id[1]+ "" +id[2]);}}
Results:
Personal Summary:
This is the water king. The last condition is different, but the solution is basically the same. The same is done by removing the same ID. To solve the experimental problem, we must make the calculation on the pen to find the appropriate algorithm.
Find the Water King continued