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