Find the Water King 2

Source: Internet
Author: User

Experimental topics

A 13-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. 2 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? (Reference core Code) 3 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? Experimental IdeasTo the three water king named Result1,result2,restult3, first give RESULT1,RESULT2,RESTULT3 assignment, that is, assign to a different three ID, if the subsequent ID and result is not the same, the times are reduced by 1, That is, three different data are removed, and the last Result1,result2,restult3 is the water king.
#include"stdafx.h"#include"iostream"using namespacestd;intMain () {inta[ -]={1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,3}; intRESULT1; intresult2; intRESULT3; inttimes1=0; intTimes2=0; inttimes3=0;  for(inti =0; I < -; i++)    {        if(times1==0) {RESULT1=A[i]; Times1=1; }        Else        {            if(a[i]==result1) {Times1++; }            Else            {                if(times2==0) {result2=A[i]; Times2=1; }                Else                {                    if(a[i]==result2) {Times2++; }                    Else                    {                        if(times3==0) {RESULT3=A[i]; Times3=1; }                        Else                        {                            if(a[i]==RESULT3) {Times3++; }                            Else{times1--; Times2--; Times3--; } }}}} cout<<"Water King Absalom:"<<endl<<result1<<endl<<result2<<endl<<result3<<Endl; return 0;}

Experiment Experience:

The experiment was really a long time, and I remember the homework I had laid out last week, and I thought about doing it today. Water King 2 is on the basis of a water king completed, last time is One-second, this is One-fourth, really enough, if you can use the most stupid method, it seems to have been solved, it must consider the complexity of time. Think about it and make it anyway.

Find the Water King 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.