Software Engineering--looking for water king

Source: Internet
Author: User

1. Topics

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 likes to post, but also reply to other ID issued by each post. 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, and the ID of the author of the Post is in it, can you quickly find the legendary water king?

2. Ideas

Starting from the first ID, and the subsequent post ID comparison, if the same counter plus one, or minus one, minus 0 after the re-assignment

3. Source code

#include "iostream.h" #define MAXSIZE 20void findwater (int id[],int len,int &water) {int counter=0;                    counter for (int i=0;i<len;i++) {if (counter==0)                //If counter is zero {water=id[i];            Record the ID of the current post as the water King suspect counter++;} Else{if (Water==id[i])        //Joshuis suspect the same as the following ID counter++;            The counter is recorded, otherwise minus one elsecounter--;}}} int main (int argc, char* argv[]) {int id[maxsize];                Post record form int num,waterking;                Number of posts, water King cout<< "Please enter the number of post:";cin>>num;cout<< "Please enter the post ID:"; for (int i=0;i<num;i++) {cin>>id[ I];} Findwater (id,num,waterking);cout<< "Water King is:" <<waterking<<endl;return 0;}

Software Engineering--looking for water king

Related Article

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.