Soft work industry looking for water king expansion

Source: Internet
Author: User

First, the topic requirements

With the development of Tan-go, found that "super Water King" no more. System-knot-fruit Table-ming, there are 3 posts a lot of IDs, their number is more than the total number of N of 1/4. Can you quickly find their ID from the list of IDs?

Second, the design idea

3 Water kings, they are more than the total number of 1/4, each time the deletion of 4 different IDs, the rest must be in line with 3 water king's hair-the number of posts are more than 1/4;

Find a location that does not have an ID of 0, then find the second location that is not 0 and not the same ID as the first one, and so on, find the fourth. Then assign four values to 0. Loop execution above, knowing that the remaining IDs are the water King's ID.

Third, the source code

#include <iostream.h>intFindintId[],intLength//encapsulate what you just wrote into a function so that it can be called multiple times{    inttrue1=1; intXiaoa=0; intxiaob=0; intXiaoc=0; intXiaod=0; intn1=0; intN2=0; intn3=0; intn4=0;  for(intI=0; i<length;i++)    {        if(id[i]!=0)//not equal to 0{Xiaoa=Id[i]; N1=i; I=length; }    }     for(i=0; i<length;i++)    {        if((id[i]!=0) && (id[i]!=Xiaoa)) {XIAOB=Id[i]; N2=i; I=length; }    }     for(i=0; i<length;i++)    {        if((id[i]!=0) && (ID[I]!=XIAOA) && (id[i]!=XIAOB)) {XIAOC=Id[i]; N3=i; I=length; }    }     for(i=0; i<length;i++)    {        if((id[i]!=0) && (ID[I]!=XIAOA) && (ID[I]!=XIAOB) && (id[i]!=XIAOC)) {xiaod=Id[i]; N4=i; I=length; }    }    //cout<<xiaoa<< "<<xiaob<<" "<<xiaoc<<" "<<xiaod<<endl; //make them all equal to 0 .//xiaoa=xiaob=xiaoc=xiaod=0;id[n1]=id[n2]=id[n3]=id[n4]=0; return 0;}intMainvoid){    intid[ -]={1,2,2,2,2,3,4,3,3,3,4,4,4}; //find (id,13); //always repeat the above function find code until there are no four different in the array, that is, only 3 water kings left    intN//Number of repetitions    intSum//How many entries does this post have?cout<<"Enter a total of a total number of bars:"; CIN>>sum; N=sum%3; //cout<<n<<endl;     for(intj=0; j<n;j++) {find (id,sum); }    //Remove the duplicate water King ID from the array//The loop puts all the arrays inside not 0 of the number output, which is 3 water Kings     for(intI=0;i< -; i++)    {        if(id[i]!=0) cout<<id[i]<<" "; } cout<<Endl; cout<<"only 3 of the results, the ID of the water king; This program also optimizes the result output, and the complexity of the time"<<Endl; return 0;}

  

Iv. Results

V. Summary

Note the difference between the remainder symbol% and the divisible symbol/use
Each parameter should be named as appropriate and annotated when necessary, so that it is clear when writing code and can be easily viewed later
The code is written, and if you have an idea to write it, so you can see it later
Every time you write a program has a gratifying sense of accomplishment, enjoy!
Although the level is not high, but has been working hard!

Soft work industry looking for water king expansion

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.