The key point is to understand: when half of the IDS are the same, deleting the two IDs at the same time takes more than half of the result IDs.
The restCodeAnd paste it as follows:
// This file is used to test the size of <br/> // different char type <br/> # include <iostream> <br/> using namespace STD; <br/> int findmost (int * ivec, int N) <br/>{< br/> int ntimes = 0; <br/> int result; <br/> for (INT I = 0; I <n; ++ I) <br/>{< br/> If (! Ntimes) <br/>{< br/> result = ivec [I]; <br/> ++ ntimes; <br/>}< br/> else <br/> {<br/> If (result = ivec [I]) <br/> ++ ntimes; <br/> else <br/> -- ntimes; <br/>}< br/> cout <"ntimes:" <ntimes <Endl; <br/> return result; <br/>}< br/> void findthreemost (int * data, int N) <br/>{< br/> int ntimes [3] = {0, 0 }; <br/> int result [3] = {0, 0 }; <br/> bool flag = false; <br/> for (INT I = 0; I <n; ++ I) <br/>{< br/> (Int J = 0; j <3; ++ J) <br/>{< br/> If (! Ntimes [J]) <br/>{< br/> result [J] = data [I]; <br/> ++ ntimes [J]; <br/> flag = true; <br/> break; <br/>}< br/> If (FLAG) <br/> continue; <br/> If (result [0] = data [I]) <br/> {<br/> ++ ntimes [0]; <br/>}< br/> else if (result [1] = data [I]) <br/>{< br/> ++ ntimes [1]; <br/>}< br/> else if (result [2] = data [I]) <br/>{< br/> ++ ntimes [2]; <br/>}< br/> else <br/> {<br/> -- ntimes [0]; -- ntimes [1]; -- ntimes [2]; <br/> If (ntimes [0] & ntimes [1] & ntimes [2] = 0) <br/> flag = false; <br/>}< br/> for (INT I = 0; I <3; ++ I) <br/> cout <result [I] <Endl; <br/>}< br/> int main () <br/> {<br/> int data [20] = }; <br/> int da [20] = }; <br/> cout <findmost (data, 20) <Endl; <br/> findthreemost (DA, 20); <br/> return 0; <br/>}
The flag in the above code is used to determine whether the current loop performs the value assignment operation. If it is not a value assignment operation, it will enter the following statement.
At this time, I really think the for... else loop design in python is the most brilliant design ......