Design ideas:
With a similar idea, just to change the ID to 3, after the ID of a number of cycles, each cycle, and id[0] the same corresponding to the repetition of +1, and id[1] the same corresponding to the repetition of +1, and id[3] the same corresponding to the repetition of +1, when id[0] the repetition of 0 o'clock, Assign the current ID to id[0], when the repetition of id[1] is 0 o'clock, assign the current ID to id[1], when id[2] is 0 o'clock, the current ID is assigned to id[2], and the 4 IDs are different, then 4 IDs are trimmed, resulting in 3 more than 1/4 IDs.
Packagehomework; Public classFind2 { Public Static voidMain (String args[]) {string id[]={"1", "2", "3", "2", "8", "2", "3", "8", "8", "3"}; Find (ID); } Public Static voidFind (String id[]) {inttimes[]=New int[3];//counterString id[]=NewSTRING[3];//3 king of water IDtimes[0]=times[1]=times[2]=0;//Repetition degreeid[0]=id[1]=id[2]=NULL; for(inti=0;i<id.length;i++) { if(Id[i]==id[0])//same as id[0] the corresponding repetition degree +1{times[0]++; } Else if(Id[i]==id[1])//same as id[1] the corresponding repetition degree +1{times[1]++; } Else if(Id[i]==id[2])//same as id[3] the corresponding repetition degree +1{times[2]++; } Else if(times[0]==0)//when Id[0] has a repetition of 0 o'clock, assign the current ID to id[0]{times[0]=1; id[0]=Id[i]; } Else if(times[1]==0)//when Id[1] has a repetition of 0 o'clock, assign the current ID to id[1]{times[1]=1; id[1]=Id[i]; } Else if(times[2]==0)//when Id[2] has a repetition of 0 o'clock, assign the current ID to id[2]{times[2]=1; id[2]=Id[i]; } Else//different than 4 IDs, 4 IDs are trimmed{times[0]--; times[1]--; times[2]--; } } for(inti=0;i<3;i++)//output water King ID{System.out.println (The "Water King" + (i+1) + "ID is:" +Id[i]); } } }
Find the Water King continued