2 solutions

  • 1
    @ 2026-8-21 15:10:12

    100分超密堆写法:

    #include<bits/stdc++.h>
    using namespace std;
    string s1,s2;
    int main(){
        getline(cin,s1);
        getline(cin,s2);
        int n=s1.size(),cnt=0;
        int m=s2.size(),k=-1;
        for(int i=0;i<n;i++) s1[i]=tolower(s1[i]);
        for(int i=0;i<m;i++) s2[i]=tolower(s2[i]);
        for(int i=0;i<m;i++){
            if(s2[i]==' ') continue;
            int j=i;
            while(j<m&&s2[j]!=' ') j++; 
            j--;
            string s=s2.substr(i,j-i+1);
            if(s==s1){
                cnt++;
                if(k==-1){
                    k=i;
                }   
            } 
            i=j;
        }
    	if(k==-1) cout<<-1;
    	else cout<<cnt<<" "<<k<<endl;
    } 
    

    Information

    ID
    434
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    7
    Tags
    # Submissions
    71
    Accepted
    14
    Uploaded By