rt,以下是代码萌新求助
#include<bits/stdc++.h>
using namespace std;
char a[1000001],c[1000001];
int f=0,s,cnt=0,location=0,cnt2=0;
bool ok=false;
bool isEqual(int f,int s){
for(int i=f,d=0;i<=s;i++){
if(a[i]!=c[d]){
return false;
}
d++;
}
return true;
}
void toLower(char a[]){
for(int i=0;i<=strlen(a);i++){
if(a[i]>='A'&&a[i]<='Z'){
a[i]=((int)a[i])+32;
}
}
}
int main(){
bool right=true;
gets(c);
gets(a);
toLower(c);
toLower(a);
for(int i=0;i<=strlen(a);i++){
if(a[i]==' ' or a[i]=='\0'){
cnt2++;
s=i-1;
if(isEqual(f,s)){
if(right==true){
location=cnt2;
right=false;
}
cnt++;
}
f=i+1;
}
}
if(cnt==0){
cout<<-1<<endl;
}else cout<<cnt<<" "<<location-1<<endl;
return 0;
}