The C + + solution array has three digits in the Super 1/4.

Source: Internet
Author: User

#include <iostream>using namespace STD;//x! the number of k factors in the intGrial (intXintK) {intRet =0; while(x) {Ret + = x/k;    x/= k; }returnRet;}intMain () {cout<< Grial (Ten,2) << Endl;return 0;}//If the number of factors in K in a n! is required, then the following rules must be met. //IE x=n/k+n/k^2+n/k^3 ... (until N/k^x is less than 0);#include <iostream>using namespace STD;intGrial (intXintK) {intCount =0;intn = x; while(n) {n &= (n-1);    count++; }returnX-count;}intMain () {cout<< Grial (3,2) << Endl;return 0;}//Find out that the number of occurrences in the array exceeds half the array. #include <iostream>using namespace STD;intGrial (intA[],intN) {intCount=0;intKey for(inti =0; I < n; i++) {if(Count = =0) {key = A[i]; Count =1; }Else{if(key = = A[i])            {count++; }Else{count--; }        }    }returnKey;}intMain () {intA[] = {1,2,3,4,5,6,3,3,3,3,3};cout<<grial (A,sizeof(a)/sizeof(int)) <<endl;return 0;}#include <iostream>//The extension of the previous topic, there are 3 number occurrences more than 1/4. using namespace STD;voidGrial (intA[],intN) {if(N <=3)return;intcount1=0, key1=0;intCount2=0, key2=0;intcount3=0, key3=0; for(inti =0; I < n; i++) {if(!count1 && Key2! = a[i] && Key3! = A[i])            {count1++;        Key1 = A[i]; }Else if(Key1 = = A[i])        {count1++; }Else  if(Key2!=a[i] && key3!=a[i])        {count1--; }if(!count2 &&key3! = A[i] && key1!=a[i])            {count2++;        Key2 = A[i]; }Else if(Key2 = = A[i])        {count2++; }Else if(Key1!=a[i] && key3!=a[i])        {count2--; }if(!count3 && key1!=a[i] && key2!=a[i])            {count3++;        Key3 = A[i]; }Else if(Key3 = = A[i])        {count3++; }Else if(Key1!=a[i] && key2!=a[i])        {count3--; }    }cout<< Key1 << Endl;cout<< Key2 << Endl;cout<< Key3 << Endl;}intMain () {intA[] = {1,5,5,5,5,2,3,1,2,2,1,1,1,2}; Grial (A,sizeof(a)/sizeof(int));return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The C + + solution array has three digits in the Super 1/4.

Related Article

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.