Looking for Water Zutai II

Source: Internet
Author: User

Title: in the last program in the Information Institute forum inside, there is a big "water king" disappeared. there were three of them, each with more than 1/4 posts. Ideas:

Or the idea of the last elimination, I defined three counters and three initial suspect water King, compare three ID, if not the same, to exclude, if the same, then the counter plus one. Suspect water King ID all with the other Navy ID to eliminate the last thing left is three water kings.

Code:
#include "iostream" using namespace std;typedef int Type;     Type find (type *shuiwang, int length) {int idcou[3]={0,0,0};//counter initialized to 0 int id[3]={0,0,0}; Water King ID initialized to 0 for (int i=0;i<length;i++)//Water King {if (idcou[0]==0 && shuiwang[i]!=id[1] && Shui            WANG[I]!=ID[2])//three number 22 compared to if not equal, then eliminate {idcou[0]=1;        Id[0]=shuiwang[i];            } else if (idcou[1]==0 &&shuiwang[i]!=id[0] && shuiwang[i]!=id[2]) {idcou[1]=1;        Id[1]=shuiwang[i];            } else if (idcou[2]==0 &&shuiwang[i]!=id[0] && shuiwang[i]!=id[1]) {idcou[2]=1;        Id[2]=shuiwang[i]; } else if (Shuiwang[i]!=id[0] && shuiwang[i]!=id[1] && shuiwang[i]!=id[2]) {Idcou            [0]--;            idcou[1]--;        idcou[2]--;        } else if (Shuiwang[i]==id[0]) {idcou[0]++;    } else if (Shuiwang[i]==id[1])    {idcou[1]++;        } else if (Shuiwang[i]==id[2]) {idcou[2]++;    }}cout<< "Three small Wang Wang are:" <<ID[0]<< "" <<ID[1]<< "" <<ID[2]<<endl; return 0;} int main () {Type shuiwang[] ={1,1,1,1,1,1,3,3,3,3,3,45,3,41,2,2,2,2,2,2};find (shuiwang,20); return 0;}

  

Looking for Water Zutai II

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.