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