#include <iostream>using namespace STD;Static intGFlags =0;//Young matrix lookup. intFindval (int(*a) [8],intXintYintVal) {inti =0;intj = y-1; while(I <=5&& J >=0) {if(A[i][j] > val) j--;Else if(A[i][j] < val) i++;Else{returnA[I][J]; }} gflags =1;return-1;}intMain () {inta[][8] = {1,2,3,4,5,6,7,8,2,3,4,5,6,7,8,9,3,4,5,6,7,8,9,Ten,4,5,6,7,8,9,Ten, One, A, -, -, the, -, -, -, +};cout<<findval (A,5,8, A) <<endl;return 0;}#include <iostream>#include <assert.h>#include <string.h>using namespace STD;//Find the first occurrence of the letter in the string. CharGrial (Char*STR) {assert (str!=null);Char*p = str;intLen =strlen(str);inti =0;Charsave[ the];//represented by a character array. memset(Save,' 0 ', the); for(; i < Len; i++) {save[str[i]]++; } while(*p! =' + ') {if(Save[*p] = =' 1 ')return*p; p++; }}intMain () {Char*S1 ="112233455667788";cout<< grial (S1) << Endl;return 0;}#include <iostream>//Find the largest subarray in the array and. using namespace STD;intGrial (intA[],intN) {inti =0;intCount =0; for(;i<n; i++) {if(Count <0) {count = A[i]; }Else{count + = A[i]; } }returnCount;}intMain () {intA[] = {-1,5,-4,7};cout<< Grial (A,4) << Endl;return 0;}//4. Minimum number of rotated arrays//title://The first element of an array is moved to the end of the array, which we call the rotation of the array. //Enter a rotation of an incrementing sorted array,//Output the smallest element in the rotated array. //For example: array {3,4,5,1,2} is a rotation of {1,2,3,4,5}, the minimum element is 1. #include <iostream>using namespace STD;Static intG_flags =0;intGrial (intA[],intN) {//two points to find. if(a[0] < A[n-1])returna[0];inti =0;intj = N-1;intMid while(I < J) {mid = (j + i)/2;if(A[mid]>a[i]) {i = mid+1; }Else if(A[mid]<a[i]) {if(Mid-1= = i)returnA[mid]; j = mid-1; }Else{intK = i; for(; k < J; k++) {if(A[k]>a[k +1])returna[k+1]; }returnA[K]; } }returnA[mid+1];}intMain () {//int a[] = {2,2,3,4,1,2}; //int a[] = {1, 1, 1, 1, 1, 1}; //int a[] = {1,1,1,1,0,1}; intA[] = {3,4,5,6,7,2};cout<< Grial (A,6) << Endl;return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C + + pen question Third Wave