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
Last time is to find a navy, this navy posts more than half of the total number of posts, this time is to find three of the Navy, the three of the Navy each person's posts exceeded the total number of 1/4, we only need to improve on the basis of the last time, the last is next to eliminate two, this time next to eliminate four, The last three remaining is the Navy.
Third, the source code
1 //Shuitong.cpp:Defines the entry point for the console application.2 //Han Xiedong3 4#include"stdafx.h"5#include"iostream.h"6 intMainintargcChar*argv[])7 {8 9 inti,j=Ten, k=1, q=1, p=1, ID1,ID2,ID3;Ten inta[Ten]={1,2,4,3,1,2,3,1,2,3}; Oneid1=a[0]; Aid2=a[1]; -id3=a[2]; - for(i=3; i<j;i++) the { - if(id1!=a[i]&&id2!=a[i]&&id3!=A[i]) - { -k=k-1; +q=q-1; -p=p-1; + if(k<=0&&q>0&&p>0) A { atid1=a[i+1]; -k=1; -i++; - } - Else if(k>0&&q<=0&&p>0) - { inid2=a[i+1]; -q=1; toi++; + } - Else if(k>0&&q>0&&p<=0) the { *id3=a[i+1]; $p=1;Panax Notoginsengi++; - } the Else if(k<=0&&q<=0&&p>0) + { Aid1=a[i+1]; thek=1; +id2=a[i+2]; -q=1; $i=i+2; $ } - Else if(k<=0&&q>0&&p<=0) - { theid1=a[i+1]; -k=1;Wuyiid3=a[i+2]; thep=1; -i=i+2; Wu } - Else if(k>0&&q<=0&&p<=0) About { $id2=a[i+1]; -q=1; -id3=a[i+2]; -p=1; Ai=i+2; + } the Else if(k<=0&&q<=0&&p<=0) - { $id1=a[i+1]; thek=1; theid2=a[i+2]; theq=1; theid3=a[i+3]; -p=1; ini=i+3; the } the } About Else if(id1==a[i]&&id2!=a[i]&&id3!=A[i]) the { theid1=A[i]; thek=k+1; + } - Else if(id1!=a[i]&&id2==a[i]&&id3!=A[i]) the {BayiId2=A[i]; theq=q+1; the } - Else if(id1!=a[i]&&id2!=a[i]&&id3==A[i]) - { theid3=A[i]; thep=p+1; the } the - } thecout<<"bucket IDs are:"<<id1<<","<<id2<<","<<id3<<Endl; the return 0; the}
Iv. Results of operation
Five, experience
Since the teacher's topic and the last time related, is on the basis of the last expansion, then the approximate method will be similar to the previous one, we just need to improve on the basis of the last time.
Test of Classroom Practice Navy (expand)