Find the Water King continued

Source: Internet
Author: User
Tags repetition

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.