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, the design idea to traverse the list of posts from beginning to end, compare the adjacent two IDs, if the same, then remember the same ID there are several, otherwise, will two IDs eliminated, while counting minus one. Third, the source code
#include <iostream.h>int main () { int arry[10]={1,1,3,3,2,2,2,2,3,3}; int id=arry[0]; int k=0; for (int i=0;i<9;) { if (Id==arry[i]) { id=arry[i]; k++; i++; } else { k--; if (k<1) { id=arry[i+1]; k=0; } i++; } } cout<<id; return 0;}
Iv. Results
Five, experimental experience
Just ask the last water king who can, from a different point of view to consider the question, can come to an answer
Find the Water king.