不要说我抄袭
2023-09-03 10:30:30
发布于:浙江
7阅读
0回复
0点赞
#include <iostream>
#include <cstring>
using namespace std;
int main(){
string s2,s;
getline(cin,s2);
getline(cin,s);
for(int i = 0;i < s.length();i++){
if(s[i] >= 'A' && s[i] <= 'Z'){
s[i] += 'a' - 'A';
}
}
for(int i = 0;i < s2.length();i++){
if(s2[i] >= 'A' && s2[i] <= 'Z'){
s2[i] += 'a'-'A';
}
}
int j;
int res = 0,res2 = -1;
for(int i = 0;i < s.length();i++){
for(j = 0;j < s2.length();j++){
if(s[j+i] != s2[j]){
break;
}
if(i>0&&s[i-1]!=' ')break;
}
if(j == s2.length() && (s[i+j] == ' ')){
res++;
if(res == 1){
res2 = i;
}
}
}
if(res != 0){
cout << res << " "<< res2;
}else{
cout << "-1";
}
return 0;
}
这里空空如也
有帮助,赞一个