Find the Water King continued

Source: Internet
Author: User

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

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.