First, the topic
A three-person line designed a forum for irrigation. Information college students like to exchange irrigation above, legend in the forum there is a "water king", he not only likes to post, but also reply to other ID issued by each post. The "Water King" has been rumored to have posted more than half the number of posts. If you have a list of posts (including replies) for the current forum, and the ID of the author of the Post is in it, can you quickly find the legendary water king?
Second, design ideas
The main breach of the problem or the teacher gave the idea of "22 phase elimination"
Third, the source code
#include <iostream.h>void main () { int arr[19]={2,2,1,3,1,2,1,5,2,2}; The assumed ID number int shuijun = 0; int count=0; Mark for (int i=0;i<9;i++) { if (count = = 0) { Shuijun = arr[i]; Count = 1; } else { if (Shuijun = = Arr[i]) count + +; Else count--; } } cout<< "The ID of the Navy is" <<SHUIJUN<<ENDL;}
Four
V. Summary of the Experiment
The most profound thing I feel about this problem is that thinking is far ahead of programming. We tried our best to get the teacher's consent in the class, until the teacher reminded us to use two-phase elimination.
Find the Water king