First, the topic requirements
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
Three people post the number of more than One-fourth, so four a group, are not the same elimination, the last remaining is the three.
Third, design code
1#include <iostream.h>2 intMain ()3 {4 intid[Ten]={1,2,3,4,4,3,2,2,3,4};5 intId_null;//define an ID that does not exist6 intshui[3];7 inta[3];8 inti;9shui[0]=shui[1]=shui[2]=0;Tena[0]=a[1]=a[2]=Id_null; One for(i=0;i<Ten; i++) A { - if(id[i]==a[0]) - { theshui[0]++; - } - Else if(id[i]==a[1]) - { +shui[1]++; - } + Else if(id[i]==a[2]) A { atshui[2]++; - } - Else if(shui[0]==0) - { -shui[0]=1; -a[0]=Id[i]; in } - Else if(shui[1]==0) to { +shui[1]=1; -a[1]=Id[i]; the } * Else if(shui[2]==0) $ {Panax Notoginsengshui[2]=1; -a[2]=Id[i]; the } + Else A { theshui[0]--; +shui[1]--; -shui[2]--; $ } $ } -cout<<"The three water kings were:"<<Endl; -cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<Endl; the return 0; -}
Iv. results:
V. Summary of the Experiment
Fill the job. The main is to look at the students thinking and code. A few days without programming, rusty ....
Water King continues