求一道计算机二级c++考题的答案。

来源:百度知道 编辑:UC知道 时间:2024/09/21 05:13:57
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <string>

int find(char s[ ], char t[ ]) ;
void wriDat() ;
const int MAXLINE = 256;
int main( )
{
char source[MAXLINE], target[MAXLINE];
cout << "Please input a string for searching:\n";
cin.getline(source, MAXLINE);
cout << "Please input a string you want to find:\n";
cin.getline(target, MAXLINE);
int intPos = find(source, target);
if(intPos >= 0)
cout << "Finding it. The target string is at index " << intPos << " of the source string \n";
else
cout << "Not finding it.\n";
wriDat() ;
return 0;
}
int find(char s[ ], char t[ ])
{
}

/* 读取数据文件并写结果文件, 考生无需修改, 否则后果自负 */
void wriDat()
{
fstream rFile, wFile ;
c

int find (char *str, char *substr) //str为父串,substr为字串
{
int i,j,temp;
int lens=strlen(str);
int lent=strlen(substr);
for(i=0;i<=lens-lent;i++)
{
temp=i;
for(j=0;j<lent;j++,temp++)
{
if(str[temp]==substr[j])
continue;
else break;
}
if(j==lent)
return i;
}
return -1;
}