‘ ’+s+‘ ’的用法还是不太懂
是为了消除字符串可能出现空格的影响吗???
还有string容器find的用法
string.find(str)是返回第一次出现的位置
string.find(str,pos)是pos开始寻找
#include<cstdio>
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
string str1,str2;
while(getline(cin,str1))
{
int len=str1.size();
for(int i=0;i<len;i++)
{
str1[i]=tolower(str1[i]);
}
str1=' '+str1+' ';
getline(cin,str2);
int n=str2.length();
for(int i=0;i<n;i++)
{
str2[i]=tolower(str2[i]);
}
str2=' '+str2+' ';
int pos=str2.find(str1);
int num2=-1;
int num=0;
int flag=1;
while(pos!=string::npos)
{
num++;
if(flag==1)
{
num2=pos;
flag=0;
}
pos=str2.find(str1,pos+1);
}
if(num2==-1)
printf("-1\n");
else
printf("%d %d\n",num,num2);
}
return 0;
}