Looking for buckets---software engineering

Source: Internet
Author: User

First, the topic and the design idea

A three-person line designed a forum for irrigation. Information college students like to exchange water on the above, legend in the forum there is a "bucket", he not only likes to post, but also reply to the other ID issued by each post. Rumor has it that three "buckets" posted more than 1/4 of 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 bucket?

(1) The ID of the poster is stored in a one-dimensional array.

(2) using the idea of "eliminating music" games, eliminating elements with different element IDs, the last remaining is "bucket".

(3) The idea of expanding the water king, a change of 3.

(4) Output results.

Second, the source code

//Donglongyan Date: 2015.04.23#include <iostream.h>voidMain () {intarray[ One];//posted by ID    intI//count Variable    intcount[3];//number ofcount[0]=count[1]=count[2]=0; intst[3];///Bucketscout<<"************** Small program to find buckets ****************"<<Endl; cout<<"Enter the poster ID (11, the ID is replaced by an integer):"<<Endl;  for(i=0;i< One; i++) {cin>>Array[i]; }     for(i=0;i< One; i++)    {        if(count[0]==0) {st[0]=Array[i]; count[0]=1; }        Else if(count[1]==0) {st[1]=Array[i]; count[1]=1; }        Else if(count[2]==0) {st[2]=Array[i]; count[2]=1; }        Else if(st[0]==Array[i]) {count[0]++; }        Else if(st[1]==Array[i]) {count[1]++; }        Else if(st[2]==Array[i]) {count[2]++; }        Else{count[0]--; count[1]--; count[2]--; }} cout<<"the ID of three buckets is:"<<st[0]<<"  "<<st[1]<<"   "<<st[2]<<Endl;}

Iii. Results of operation

Iv. Experience

The topic is very simple, the main is how to optimize, is the time complexity of the reduction. To borrow the water king's code optimization, then the idea of eliminating music is very applicable. The programming implementation is good.

Looking for buckets---software engineering

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.