Program: Implement the operation of the string as required below:(1) Design a class that provides the following string manipulation1) Write a method that finds the number of occurrences of the specified string in a string.2) Write a method that replaces all target word trailing characters substitution strings in the parent string with parameters (female string, target string, replacement string).3) Write a method to determine whether an email address
This article describes the PHP binary lookup algorithm. Share to everyone for your reference, specific as follows:
BinarySearch
The method used in the binary lookup is relatively easy to understand, taking an array as an example:
① first takes the value in the middle of the array floor (LOW+TOP)/2),
② then, by comparing the number you want to find, if it is l
* @author CYXL * */public class BinarySearch {private int rcount=0;
private int lcount=0;
/** * Get Recursion number * @return * * public int getrcount () {return rcount;
/** * Get the number of loops * @return/public int getlcount () {return lcount; /** * Performs a recursive binary lookup that returns the first occurrence of this value * @param sorteddata
the layer;.
8. Back to frame 1th, add the following action to the submit button in the input interface:
On (release) {
Namecount = number (Namecount) +1;
Set ("Name" Add Namecount, entered);
temp = eval ("name" Add Namecount);
names = names Add namecount add "." Add temp add newline;
entered = "";
}
Add an action to the lookup button; On (release) {
file Find Description:Find eligible files on the file systemLocate: Non-real-time lookup, through the database to find, high efficiency, can be used to find more fixed filesDepending on the/var/lib/mlocate/mlocate.db database file, the files created before the database point in time can be found, and the newly created files cannot be searched after the point-in-time.Update this database file: Update It once a day, or use UpdateDB to update the databas
Discuss the structure in depth by using a table lookup program.
When you encounter a macro definition #define in 1 o'clock, what does the macro processor and the compiler do with it? You need to deposit the name in and replace text 1 in a table, when appearing in as "Statet = in";
You must replace in with a.
1 processing the name requires that the name and replacement text be stored in the table. Use function Install (S,T) to implement. After the enco
;k) {//If the value of the current number is greater than k
BINSEARCH2 (A,LOW,MID-1,K)//Call recursive algorithm
}
else if (a[mid]BINSEARCH2 (A,MID+1,HIG,K)//Call recursive algorithm
}
}
}
int main () {
int a[10001];//defines an array for storing elements
int n,i=0;//defines a number of storage and counters
printf ("Please enter the number of elements you want to
Pos in the current string to a character array starting with S, returning the number of actual copiescharacter Description of string:int capacity () const; Returns the current capacity (that is, the number of elements in a string that do not have to increase memory)int max_size () const; Returns the length of the largest string that can be stored in a string objectint size () const; Returns the size of the
first time*/ -H= (D1+S1)%m; -D=D1; - while(Ht[h]) - { - /*resolve the second and subsequent conflicts*/ intemp=D; -D= (temp+ (7*key)%Ten+1)%m;/*calculate di (i=2,3.)*/ toH= (s1+d)%m; + } -ht[h]=key; the * } $ intSearchhash (intHt[],intkey)Panax Notoginseng { - /*find the key in the hash list, return the comparison number if found, otherwise return-1*/ the intd,s1,d1,h,temp,sum; +H=Hash (key); AS1=h;d1=s1;d=D1; the if
If the lookup succeeds, the remainder of the string (from the matching point) is returned, and false is returned if the string is not found.
Version support: PHP
Grammar:
Stristr (String,find)
Description
string is required. Specifies the string to be searched.
Find required. Specifies the character to find. If the parameter is a number, the character that matches the ASCII value of the
number of records whose keywords are compared with the given values.
Applicability: Sequential search is generally applicable when there is a small amount of data.
Advantages:
1. Simple Algorithm Implementation and wide adaptability
2. There is no requirement on the structure of the table, regardless of whether the records are sorted by keywords.
3. It is applicable to ordered tables and single-chain tables.
Disadvantages:
1. The average search leng
a simple look at the manual.1, Strrpos (), calculates the position of the last occurrence of the specified string in the target string2, Strripos (), calculates the position of the last occurrence of the specified string in the target string (case insensitive)Summary: Note that these functions will return false if not found, so in determining whether the two sides are equal (if), pay attention to both sides of the type, the above several functions, is more commonly used in PHP string
a simple look at the manual.1, Strrpos (), calculates the position of the last occurrence of the specified string in the target string2, Strripos (), calculates the position of the last occurrence of the specified string in the target string (case insensitive)Summary: Note that these functions will return false if not found, so in determining whether the two sides are equal (if), pay attention to both sides of the type, the above several functions, is more commonly used in PHP string
string more than once, the string must be made up of an item. The way to form an item is to precede it with "\ (", followed by "\"). So this command:/\ (ab\) *Matches: "AB", "Abab", "Ababab", and so on. and also match "".To avoid matching empty strings, use "\+". This means that the preceding item can be matched one or more times./ab\+Match "AB", "ABB", "abbb", etc. It does not match "a" followed by "B".To match an optional option, use "\=". For example:/folders\=Match "folder" and "Folders".4,
One or two points find1 defErfen_search (para1,find_num):2 " "3 Two-point search4 :p Aram Para1: A range to find, such as a list or a tuple5 :p Aram Find_num: The number to find6 : return:7 " "8Mid_index = Len (para1)//29Mid_num =Para1[mid_index]Ten Try: One ifFind_num = =Mid_num: A Print('got it.') - elifFind_num >Mid_num: -PARA1 = para1[mid_index+1:] the Erfen_search (para1,find_num) - elifFind_num Mid
form an item is to precede it with "\ (", followed by "\"). So this command:/\ (ab\) *Matches: "AB", "Abab", "Ababab", and so on. and also match "".To avoid matching empty strings, use "\+". This means that the preceding item can be matched one or more times./ab\+Match "AB", "ABB", "abbb", etc. It does not match "a" followed by "B".To match an optional option, use "\=". For example:/folders\=Match "folder" and "Folders".4, specify the number of repet
Insertionsort_2 (T *a, int n){A[0] used to save sorted usage and not save raw datafor (int j=2; j{T temp = a[j];Insert (temp,a,j-1);A[0] = temp;int i = j-1;while (temp //{A[I+1] = A[i];i--;//}A[I+1] = temp;}}Templatevoid Insert (const t E, T *a, int i){A[0] = e;while (E{A[I+1] = A[i];i--;}A[i+1] = e;}
Binary find
One: C language version sequential linear lookup recursive iterative lookup
#include int b
Look up the function, you must have used, but for some more complex replacement requirements, you can use to find a calm response? For example, a netizen downloads a chemical test paper from the Internet, some of which do not use the correct format, such as the molecular formula of sodium sulfate is written in Na2SO4, Now we have to change the number of all the formula in the test paper to subscript, what should we do? You know, if you simply select a
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.