早教吧作业答案频道 -->英语-->
ImplementYourOwnStringClassUsingKMPTaskYourtaskissupposedtowriteastringclassofyourown.Andyourimplementationshouldatleastprovidethefollowingfunctions:string&insert(sizetpos1,conststring&str);Insertsacopyoftheent
题目详情
Implement Your Own String Class Using KMP
Task
Your task is supposed to write a string class of your own.And your implementation should at least provide the following functions:
string& insert ( size_t pos1,const string& str );
Inserts a copy of the entire string object str at character position pos1.
string& insert ( size_t pos1,const char * s,size_t n );
Inserts at the character position pos1,a copy of the string formed by the first n characters in the array of characters pointed by s.
string& erase ( size_t pos = 0,size_t n = npos );
Erases a sequence of n characters starting at position pos.Notice that both parameters are optional:with only one argument,the function deletes everything from position pos forwards,and with no arguments,the function deletes the entire string.
string& replace ( size_t pos1,size_t n1,const string& str );
The section,which begins at character position pos1 and spans for n1 characters within the string is replaced by a copy of the entire string object str.
string& replace ( size_t pos1,size_t n1,const char * s,size_t n2 );
The section,which begins at character position pos1 and spans for n1 characters within the string is replaced by a copy of the first n2 characters in the array of characters pointed by s.
void swap ( string& str );
Swaps the contents of the string with those of string object str,such that after the call to this member function,the contents of this string are those which were in str before the call,and the contents of str are those which were in this string.
string& operator+= ( const string& str );
string& operator+= ( const char* s );
Appends a copy of the argument to the string.
Find content in string
Searches the string for the content specified in either str,s or c,and returns the position of the first occurrence in the string.
size_t find ( const string& str,size_t pos = 0 ) const;
str string to be searched for in the object.The entire content of str must be matched in some part of the string to be considered a match.
pos Position of the first character in the string to be taken into consideration for possible matches.A value of 0 means that the entire string is considered.
size_t find ( const char* s,size_t pos,size_t n ) const;
s Array with a sequence of characters.
pos Position of the first character in the string to be taken into consideration for possible matches.A value of 0 means that the entire string is considered.
n Length of sequence of characters to search for,in other words only the first n characters of array s should be considered.
Finally,your main function is supposed to test all of the function of your implementation.
Task
Your task is supposed to write a string class of your own.And your implementation should at least provide the following functions:
string& insert ( size_t pos1,const string& str );
Inserts a copy of the entire string object str at character position pos1.
string& insert ( size_t pos1,const char * s,size_t n );
Inserts at the character position pos1,a copy of the string formed by the first n characters in the array of characters pointed by s.
string& erase ( size_t pos = 0,size_t n = npos );
Erases a sequence of n characters starting at position pos.Notice that both parameters are optional:with only one argument,the function deletes everything from position pos forwards,and with no arguments,the function deletes the entire string.
string& replace ( size_t pos1,size_t n1,const string& str );
The section,which begins at character position pos1 and spans for n1 characters within the string is replaced by a copy of the entire string object str.
string& replace ( size_t pos1,size_t n1,const char * s,size_t n2 );
The section,which begins at character position pos1 and spans for n1 characters within the string is replaced by a copy of the first n2 characters in the array of characters pointed by s.
void swap ( string& str );
Swaps the contents of the string with those of string object str,such that after the call to this member function,the contents of this string are those which were in str before the call,and the contents of str are those which were in this string.
string& operator+= ( const string& str );
string& operator+= ( const char* s );
Appends a copy of the argument to the string.
Find content in string
Searches the string for the content specified in either str,s or c,and returns the position of the first occurrence in the string.
size_t find ( const string& str,size_t pos = 0 ) const;
str string to be searched for in the object.The entire content of str must be matched in some part of the string to be considered a match.
pos Position of the first character in the string to be taken into consideration for possible matches.A value of 0 means that the entire string is considered.
size_t find ( const char* s,size_t pos,size_t n ) const;
s Array with a sequence of characters.
pos Position of the first character in the string to be taken into consideration for possible matches.A value of 0 means that the entire string is considered.
n Length of sequence of characters to search for,in other words only the first n characters of array s should be considered.
Finally,your main function is supposed to test all of the function of your implementation.
▼优质解答
答案和解析
你想表达什么,是关于kmp模式匹配的英文算法描述吗!
中文的早看懂了.
中文的早看懂了.
看了 ImplementYourO...的网友还看了以下:
这两句JS的代码什么意思?A.varstr=myform.tel.value;if(str.sub 2020-04-08 …
为什么这个语句有错误,我被这个语句弄的有点懵:看下面:char*str;str=‘a’;为什么这样 2020-05-16 …
C语言,为什么?voudmain(){char*str="Good\nnight!";puts(s 2020-05-17 …
ImplementYourOwnStringClassUsingKMPTaskYourtaskis 2020-05-17 …
若定义charstr[2][3];则下列表达式不能表示str[1][0]的地址的是.A.str+1 2020-06-24 …
.以下选项中有语法错误的是A.char*str[]={“guest”};B.charstr[][1 2020-07-22 …
RegExp(str)===RegExp(str)为什么是false(正则表达式)RT,返回的是f 2020-07-23 …
不会改错了……#includevoidmain(){charstr[80];scanf("%s", 2020-07-23 …
Hex(ascw(Strone)Mid(Str,i,1)Hex(ascw(Strone)Mid(St 2020-11-01 …
咨询一下删除字符串的解释str=str.replace(/(&|\?)spm=[^&]*(&|$)/ 2020-11-01 …