First, the topic requirements
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, design ideas
The topic is in the last search for "water king" on the basis of expansion, design ideas and the last similar, the last to find water king is a water king variable, a count variable, then the design of the idea of the last technique, there are three of the navy variables, three count variables, respectively, the Navy's three variables and the next number comparison, Then the count variables corresponding to the three navy are counted separately, the same is added one, the difference is offset minus one; in turn, the rule of the water King is similar, finally found 3 Navy
Third, the program code
1#include"stdafx.h"2 3 voidFindshuijun (intArrid[],intnum)4 {5 intshuijun1=0, shuijun2=0, shuijun3=0;6 intx1=0, x2=0, x3=0;7 for(intI=0; i<num;i++)8 {9 if(x1==0&& arrid[i]!=shuijun2 && arrid[i]!=shuijun3)Ten { Onex1=1; Ashuijun1=Arrid[i]; - } - Else if(x2==0&& arrid[i]!=shuijun1 && arrid[i]!=shuijun3) the { -X2=1; -Shuijun2=Arrid[i]; - } + Else if(x3==0&& arrid[i]!=shuijun1 && arrid[i]!=shuijun2) - { +x3=1; Ashuijun3=Arrid[i]; at } - Else if(arrid[i]!=shuijun1 && arrid[i]!=shuijun2 && arrid[i]!=shuijun3) - { -x1--; -x2--; -x3--; in } - Else if(arrid[i]==shuijun1) to { +x1++; - } the Else if(arrid[i]==shuijun2) * { $x2++;Panax Notoginseng } - Else if(arrid[i]==shuijun3) the { +x3++; A } the } +printf"The IDs of the three Navy were:%d,%d,%d\n", SHUIJUN1,SHUIJUN2,SHUIJUN3); - $ } $ - - the intMainintargcChar*argv[]) - {Wuyi intarry[ the]={ the, the,111, the,113,111,111, the, the, the, the, the,111,113, the}; theFindshuijun (Arry, the); - return 0; Wu}
Iv. implementation of the program
Five, experience
The result is not correct, after debugging found that the navy and the count variable is not initialized; This experiment was discussed with the students, in the setting of the variable when the first encountered difficulties, and then a little analysis before the final solution.
Homework-Finding the Navy