Find the Water King continued

Source: Internet
Author: User

I. Contents of the topic

A three-person line designed a forum for irrigation. Information college students like to exchange irrigation above, legend in the forum there is a "water king", he not only like to post,

It will also reply to each post sent by other IDs. The "Water King" has been rumored to have posted more than half the number of posts. If you have a list of posts (including replies) for the current forum,

The ID of the author of the Post is also in it, can you quickly find the legendary water king?

Second, the design of the idea on the previous basis, in the expansion of 3, add three suspected targets, to traverse

Third, the experimental code

Package Com.minirisoft;import Java.util.scanner;public class Shukkesan {public static void Findwater (int[] ID, int len,in                    T[] water) {int[] counter=new int[3];        Counter counter[0]=counter[1]=counter[2]=0;    Water[0]=water[1]=water[2]=-1;              Initialize list of suspects for (int i=0;i<len;i++) {if (counter[0]==0)//assignment First {              counter[0]++;           Water[0]=id[i];               } else if (counter[1]==0) {counter[1]++;            Water[1]=id[i];              } else if (counter[2]==0) {counter[2]++;            Water[2]=id[i];            } else if (id[i]==water[0])//If the counter is 0, re-assign the value {counter[0]++;            } else if (Id[i]==water[1]) {counter[1]++;            } else if (Id[i]==water[2]) {counter[2]++;               } else         If the ID of the three suspects is different, then three counters are reduced by one until counter is 0 {counter[0]--;              counter[1]--;            counter[2]--;       }}} public static void Main (string[] args) {int[] id=new int[100]; Post record form int[] Waterking=new int[3];  Number of posts, buckets Scanner input=new Scanner (system.in);  System.out.println ("Please enter the number of posts:");  int Num=input.nextint ();  System.out.println ("Please enter the Post ID:");  for (int i=0;i<num;i++) {id[i]=input.nextint ();  } findwater (id,num,waterking);  SYSTEM.OUT.PRINTLN ("Bucket is:");  for (int i=0;i<3;i++) {System.out.println (waterking[i]+ "");   } System.out.println (); }}

Four, the experiment

V. Summary of the Experiment

I did not do it, ask the students to do it, feel their own programming thinking, not so flexible.

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.