70分求助
查看原帖
70分求助
1209497
Will_K楼主2024/9/9 21:59
#include<bits/stdc++.h>
using namespace std;
string s;
string art;
bool vis=1,t=1;
int num=0;
int location=0;
int main(){
    getline(cin, s);
    getline(cin,art);
    int len1=s.length();
    int len2=art.length();
    int l=0;
    for(int i = 0 ; i <= len2;){
        if(vis){
            if(s[l]==art[i]||s[l]==art[i]+32||s[l]==art[i]-32){
                l++;
                i++;
                if(l==len1){
                    if(art[i]==' ' || i==len2){
                        num++;
                    }
                    l=0;    
                if(t){
                    location=i-len1;
                    t=false;
                }
                }
            }
            else{
                vis=false;
                l=0;
            }
        }
        else{
            if(art[i]==' ')
                vis=1;
            i++;
        }
    }
    if(num){
        cout<<num<<' '<<location<<endl;
    }
    else
        cout<<-1<<endl;

    return 0;
}
2024/9/9 21:59
加载中...