April 24 Friday Classroom Exercise: Find the Water king continued

Source: Internet
Author: User

First, the topic requirements

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? With the development of the Forum, the administrator found that the water king did not, but the statistical results show that there are three posts a lot of ID. According to the statistics of their posts more than 1/4, you can quickly find them from the list of posts? Second, the design idea three, the program code
#include <iostream> #include <assert.h>using namespace Std;int * Search (int *userid,int n) {int curid[3]={0 };//the number of three different idint currently saved curnum[3]={0};//the current three different IDs; for (int i=0;i<n;i++) {if (curnum[0]==0&&userid[i]!= CURID[1]&AMP;&AMP;USERID[I]!=CURID[2])//user ID does not have the same ID in the current ID and the current number of userid[0] is 0; {curnum[0]=1;curid[0]=userid[i];} else if (curnum[1]==0&&userid[i]!=curid[0]&&userid[i]!=curid[2]) {curnum[1]=1;curid[1]=userid[i];} else if (curnum[2]==0&&userid[i]!=curid[0]&&userid[i]!=curid[1]) {curnum[2]=1;curid[2]=userid[i];} else if (userid[i]==curid[0])//user ID and current ID are the same as the current ID number +1{curnum[0]++;} else if (userid[i]==curid[1]) {curnum[1]++;} else if (userid[i]==curid[2]) {curnum[2]++;} else if (userid[i]!=curid[0]&&userid[i]!=curid[1]&&userid[i]!=curid[2])//Four IDs together offset {curNum[0]--; curnum[1]--;curnum[2]--;}} Return curid;//returns the current remaining three IDs as three water Kings}void main () {int N;int * userid;int curid[3]={0};int curnum[3]={0};int i;cout<< " Input number of posts: "; Cin>>n;assert (n>0); userId=new int[n];cout<< "Enter each drip post ID:" <<endl;for (i=0;i<n;i++) {cin>>userid[i];} for (i=0;i<3;i++)//Output three water King Id{cout<<*search (userid,n) +i<< "\ T";}}
Four, the procedure five, the experimental summary procedure has the question, has not found the correct solution at present. This semi-finished product can only be uploaded and later updated. It is more difficult to find water Wang Yu than to find water king. The method of finding the water king is easy to find by analogy. But the elimination of the method, in code difficult to achieve. Because there are a lot of exceptions. For example, 11111111112222345666666777777777895. Satisfying test instructions, but it is difficult to achieve with elimination method.

April 24 Friday Classroom Exercise: 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.