10分求助
查看原帖
10分求助
538243
123rrc楼主2023/8/4 23:00
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
string lw(string s){
    for(int i=0;i<s.length();i++){
        if(s[i]>='A'&&s[i]<='Z'){
            s[i]-='A';
            s[i]+='a';
        }
    }
    return s;
}
int main(){
    getline(cin,s1);
    getline(cin,s2);
    s1[s1.length()-1]=' ';
    s1=' '+s1;
    s2=' '+s2+' ';
    s1=lw(s1);
    s2=lw(s2);
    int find=0,pos=-1,p0;
    while(1){
        pos=s2.find(s1,pos+1);
        if(!find){
            if(pos<s2.length()){
                find=1;
                p0=pos;
            }else{
                break;
            }
        }else{
            if(pos>=s2.length()){
                break;
            }else{
                find++;
            }
        }
    }
    if(!find){
        cout<<-1;
    }else{
        cout<<find<<" "<<p0;
    }
    return 0;
}

记录,只过了#2,但IDE自己造了许多数据(包括:文章前有空格,单词之间有 ≥2\geq2 个空格),没发现错误

2023/8/4 23:00
加载中...