robin88 • 4个月前
using namespace std; / run this program using the console pauser or add your own getch, system("pause") or input loop /
int main(int argc, char** argv) {
string bj;
string fg;
getline(cin,bj);
getline(cin,fg);
for (int i = 0; i < bj.length(); i++)
{
bj[i] = tolower(bj[i]);
}
for (int i = 0; i < fg.length(); i++)
{
fg[i] = tolower(fg[i]);
}
// 大写字母转小写字母
bool f=true;
int j=0,ans=0,first=0,m=0;
for(int i=0;i<fg.size()+1;i++)
{
if(bj[j]=='\0' && (fg[i]==' '|| fg[i]=='\0') && f==true)
{
ans++;
if(ans==1)
{
m=i-bj.length();
}
}
if(fg[i]==' ')
{
f=true;
j=0;
continue;
}
if(f)
{
if(bj[j]==fg[i])
{
j++;
}
else
{
f=false;
}
}
}
if(ans==0)
{
cout<<-1;
return 0;
}
cout<<ans<<' '<<m;
return 0;
}
评论:
请先登录,才能进行评论