First, the topic
A three-person line designed a forum for irrigation. 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
The idea of this experiment is similar to the previous one, through the "elimination of music" way to solve the problem, but this time the number of water king increased to three, so the number of comparisons will also increase, and to set corresponding variables to record the process of comparison.
Third, the source code
#include <iostream.h>void Data (int L,IntA[]);IntMain () {int l;//Lengthint target[3]={0,0,0};int id[3]={-1,-1,-1}; cout<<"*********************************************************"<<Endl cout<<"Please enter the number of posts:"; Cin>>L cout<<"*********************************************************"<<Endlint * shuiwang=NewInt[L]; Data (L,shuiwang);Forint i=0;i<l;i++) {if (target[0]==0 && shuiwang[i]!=id[1] && shuiwang[i]!=id[2]) {target[0]=1; id[0]=Shuiwang[i]; }Elseif (target[1]==0 && shuiwang[i]!=id[0] && shuiwang[i]!=id[2]) {target[1]=1; id[1]=Shuiwang[i]; }Elseif (target[2]==0 && shuiwang[i]!=id[0] && shuiwang[i]!=id[1]) {target[2]=1; id[2]=Shuiwang[i]; }Elseif (shuiwang[i]!=id[0] && shuiwang[i]!=id[1] && shuiwang[i]!=id[2]) {target[0]--; target[1]--; target[2]--; }Elseif (shuiwang[i]==id[0]) {target[0]++; }Elseif (shuiwang[i]==id[1]) {target[1]++; }Elseif (shuiwang[i]==id[2]) {target[2]++; }} cout<<"*********************************************************"<<Endl cout<<"Water Wang Yi for:"<<id[0]<<Endl cout<<"Water King II is:"<<id[1]<<Endl cout<<"Water Wang San for:"<<id[2]<<endl; Cout<<** endl; return 0; void Data (int l,int< Span style= "color: #000000;" > a[]) {cout<< " "<<ENDL; for (int i=0;i<l;i+ +a[i];}
Four, the experiment
V. Summary of the Experiment
The experiment compared the previous one with a new step, finding more than one person in the global context. Added difficulty, on the basis of the original, carried out in depth. In fact, the idea is still the same, but there is a corner, in the beginning how can not think out. This experiment classmate to my help very much, I also was on the basis of reference to complete this experiment.
Find the Water King (ii)