Beauty of programming-posting and scalability

Source: Internet
Author: User

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 ......

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.