Experimental topics
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?
Experimental ideas
Since the water King's post and the number of replies are more than half, then we just need to sort all the ID number in the array, and then find the ID in the middle of the array must be the water King ID, but this method is to be optimized. Put all the IDs according to the order of posting and replies in the array, and then call a loop to start the traversal, two adjacent to the comparison, if not the same will be eliminated, in the array of numbers also changed along with it, know that in the end will find the water king.
Experiment Code
//Letter 1201-2 Division new Red#include"stdafx.h"#include"iostream"using namespacestd;intMain () {inta[Ten]={1,3,2,3,2,3,1,3,3}; intresult = a[0]; intTimes =1; for(inti =1; I <Ten; i++) { if(A[i] = =result) times++; Else Times--; if(Times = =0) {result=A[i]; Times=1; }} cout<<"Water King Absalom:"<<result<<Endl; return 0;}
Experiment Experience:
This experiment is very interesting, not very difficult, but there are very interesting points of thinking, like the problem.
Find the Water king