# Software Engineering Classroom Training ——— find three of the Kings

Source: Internet
Author: User

I. Description of the topic

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?

Second, the solution of ideas

Follow the idea of the last elimination, define three counters and three suspected water King, compare three ID, if not the same, exclude, if the same, then the counter plus one. The ID of the suspected water King is offset with the other Navy IDs. The last thing left is three water kings.

Third, the program code

`//shuiba.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include"iostream"intMain () {intlength; intidcou[3]={0,0,0};//counter initialized to 0    intid[3]={0,0,0};//Water King ID initialized to 0printf"Please enter the number of posts:"); scanf ("%d",&length); int* shuiwang=New int[length]; printf ("Please enter the ID of all the people posting:");  for(intj=0; j<length;j++)//enter ID{scanf ("%d",&Shuiwang[j]); }     for(intI=0; i<length;i++)//Find the Water king    {        if(idcou[0]==0&& shuiwang[i]!=id[1] && shuiwang[i]!=id[2]) {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]++; }} printf ("the ID of three water Kings is: \ n"); printf ("%d\t%d\t%d\t\n", id[0],id[1],id[2]); return 0;}`

Iv. Results of operation

Five, experience

There are a lot of similarities between the three water kings and a water king, but the problem is wrong at first, and then the cause of the problem is found and some of the possibilities are ignored. After two exercises to find the water king, I think the most bull is not to find the best way to solve the problem, but the person who is behind the scenes.

Software Engineering Classroom Training ——— find three of the Kings

Related Keywords:
Related Article

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.