Class practice-Find water King continued

Source: Internet
Author: User

First, the topic

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, design ideas:

This problem and the original question basically similar can be used to eliminate the idea. The previous question is 22 comparison which can be compared three. If not the same, then eliminate, if the same, add one.

Third, the source code

#include"stdafx.h"#include"iostream.h"#defineMAXSIZE 30voidFind (intId[],intLenintwater[]) {    intcounter[3]; counter[0]=counter[1]=counter[2]=0; water[0]=water[1]=water[2]=-1;  for(intI=0; i<len;i++)    {        if(counter[0]==0) {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]) {counter[0]++; }        Else if(id[i]==water[1]) {counter[1]++; }        Else if(id[i]==water[2]) {counter[2]++; }        Else{counter[0]--; counter[1]--; counter[2]--; }    }}intMainintargcChar*argv[]) {    intId[maxsize]; intnumber,waterid[3]; cout<<"Please enter the number of posts:"; CIN>>Number ; cout<<"Please enter the Post ID:";  for(intI=0; i<number;i++) {cin>>Id[i];    } Find (Id,number,waterid); cout<<"The Water king is:";  for(i=0;i<3; i++) {cout<<WaterId[i]<<" "; } cout<<Endl; return 0;}

Four

V. Summary

This time the topic is similar to the previous one, the last time was two two elimination, and this time is three three eliminate. The specific writing process and the last time is a little different. There is a lot to learn by discussing and finding information with classmates.

Class practice-Find 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.