题目描述 Description
给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置。
输入描述 Input Description
仅一行包含两个字符串a和b
输出描述 Output Description
仅一行一个整数
样例输入 Sample Input
abcd bc
样例输出 Sample Output
2
数据范围及提示 Data Size & Hint
字符串的长度均不超过100
Pascal用户请注意:两个字符串之间可能包含多个空格
#include "iostream"
#include<string.h>
using namespace std;
main()
{
int i,j,k;
char a[100],b[100];
cin>>a>>b;
for(i=0;i<100;i++)
{
if(a[i]==b[0])
{
k=i+1;
for(j=1;j<strlen(b);)
{
if(a[i+j]==b[j])
{
k=i+1;
j++;
}
else
{
k=0;
break;
}
}
if(j==strlen(b))
{break;}
}
}
cout<<k;
}