|
<>说明一下,</P>
<>题目是这样的:匹配搜索程序的编写,先根据用户的输入建立一个字符串,再提示用户输入另一个字符串,在原串中的搜索是否在与此相同的子串,若存在,给出此子串的起始位置,否则,给出没有找到的信息</P>
<>#include <iostream.h><BR>#include <string.h></P>
<P>class string<BR>{<BR>private:<BR>int sign,i,j,point;<BR>char strsource[50],straim[32];<BR>public:<BR>string(char source[50],char aim[32])<BR>{<BR>strsource[50]=source[50];<BR>straim[32]=aim[32];<BR>}<BR>void output();<BR>void bijiao();<BR>};<BR>string::string(char source[50],char aim[50])<BR>{<BR>int i=0,point;<BR>cout<<"input the source str:"<<endl;</P>
<P>for(i=0;i<=50;i++)</P>
<P>{cin>>source;<BR>i++;point=i;<BR>strsource[point]=source;}<BR>cout<<"input the straim:"<<endl;<BR>for(j=0;j<=6;j++)<BR>{cin>>aim;<BR>i++;point=i;<BR>straim[point]=aim;<BR>}};<BR>void output(char strsource,char straim)<BR>{int i,j;<BR>for(i=0;i<=(strlen(strsource));i++)<BR>cout<<strsource<<endl;<BR>for(j=0;j<=(strlen(straim));j++)<BR>cout<<straim<<endl;<BR>};<BR>void bijiao(char strsource,char straim)<BR>{int i,j,point,sign;<BR>for(i=0;i<(strlen(strsource)-strlen(straim));i++)<BR>{point=i;<BR>sign=1;<BR>for(j=0;j<strlen(straim);j++,point++)<BR>{if(strsource[point]!=straim[j])<BR>{sign=0;<BR>break;<BR>}<BR>}<BR>if(sign==1)<BR>{cout<<"find!the location is %d\n"<<i+1<<endl;break;}<BR>if(!sign)<BR>{cout<<"No find!\n";}<BR>}</P>
<P>void main()<BR>{<BR> string str;<BR>str.output(char,char);<BR>str.bijiao(char,char);<BR>}</P> |
|