A few questions

Source: Internet
Author: User

 

1. Draw n elements from a continuous array of values to find which elements are called

# Include "stdafx. H "# include <iostream> using namespace STD; int _ tmain (INT argc, _ tchar * argv []) {int A [100] = {0 }; // truncate 3, 4, 57 int B [100] = {0}; // original array, [0, 99] For (INT I = 0; I <sizeof (a)/sizeof (A [0]); ++ I) {if (I> 2 & I <55) A [I] = I + 2; else if (I> = 55) A [I] = I + 3; else a [I] = I; B [I] = I;} const int n = 3; int arr [N] = {0}; int nindex = 0; int K = 0; Int J = 0; For (k = 0, j = 0; K <(sizeof (a)/sizeof (A [0])-N) & J <sizeof (B)/sizeof (B [0]); ++ J) {if (a [k]! = B [J]) Arr [nindex ++] = B [J]; else ++ K; If (sizeof (ARR)/sizeof (ARR [0]) = nindex) break;} cout <"\ n print the value \ n"; for (INT I = 0; I <sizeof (ARR) /sizeof (ARR [0]); ++ I) cout <arr [I] <Endl; return 0 ;}

 

 

 

Running result

 

 

 

 

2. An array a [n + 1] with an element value of [1, N] to find any repeated element.

# Include "stdafx. H "# include <iostream> using namespace STD; /*************************************** * **********************************/* int array arr [n + 1], the value range of the array element is [1, N]. The idea of finding any repeated numbers is: First FAST sort, O (nlogn), then traverse from the beginning, find the first a [I] = A [I + 1], that is, the minimum (large) of the first repeat) value element /************************************* * **********************************/INT partition (int arr [], int low, int high) {int I = low; Int J = high; int priovt = arr [I]; while (I <j) {// find the first element smaller than privot on the right and place it in the low position while (I <J & arr [J]> = priovt) -- J; if (I <j) Arr [I] = arr [J]; // find the first element on the left that is greater than privot, place it in the high position while (I <J & arr [I] <= priovt) + + I; if (I <j) arr [J] = arr [I];} arr [I] = priovt; return I;} void quicksort (INT arr [], int low, int high) {If (null = ARR) return; If (low 

 

 

 

Running result

 

 

3. The following table lists the users who have performed more than (inclusive) operations since January 1, August 2, 2014.

 

 select * from (  select usr, count(usr) as times from tbl_users where dt>‘2014-08-02‘  group by usr ) t   where times >= 3  

 

 

 

Running result

 

 

 

 

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.