有追加分 帮忙编写一个程序用VC6.0.

来源:百度知道 编辑:UC知道 时间:2024/05/10 11:16:16
编写个程序介绍2个字符串,判断第1个字符串中是否包含第2个字符串,如果包含说明第2个字符串在第1个字符串的位置。

#include<stdio.h>
#include<string.h>
#define MAXLEN 100
main()
{
int i=0,j,len_line,len_key;
char line[MAXLEN],key[MAXLEN];

scanf("%s",line);
printf("Your line:%s\n",line);
scanf("%s",key);
printf("Your key:%s\n",key);

len_line=strlen(line);
len_key=strlen(key);
len_line-=len_key;

while(j=0,i<=len_line)
{
while(j!=len_key&&*(line+i+j)==*(key+j++));
if(i++,j==len_key)printf("%d\n",i);
}
}

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
string s1,s2;
cin>>s1>>s2;

int i=search(s1.begin(),s1.end(),s2.begin(),s2.end())-s1.begin();

if(i==s1.size())
cout<<"Can't find it.";
else
cout<<i;
cin>>i;
}