奇怪的是,明明我判断了str2[i]是否为空格,但判断似乎没有起作用?
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
string str1,str2,str3;
getline(cin,str1);
getline(cin,str2);
int pos=-1;
int num=0;
int tag=1;
char c=' ';
for(int i=0;i<str2.size();i++)
{
if(str2[i]==c);
{
if(str3.size()==str1.size())
{
for(int j=0;j<str3.size();j++)
{
if(tolower(str1[j])!=tolower(str3[j])) tag=0;
}
if(tag==1) num++;
}
if(num==1) pos=i;
str3.clear();
}
str3=str3+str2[i];cout<<str3<<endl;
}
if(pos!=-1)
{
cout<<num<<" "<<pos;
}
else cout<<"-1";
return 0;
}