1 solutions

  • 0
    @ 2025-11-5 17:14:24

    C++ :

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<cctype>
    #include<algorithm>
    using namespace std;
    string word,str;
    int main()
    {
        int first=0,ans=0;
        cin>>word;
        word=" "+word+" ";
        for(string::size_type i=0;i!=word.size();i++)
         word[i]=toupper(word[i]);
           //如果c为小写英文字母,则返回对应的大写字母;否则返回原来的值。
        getline(cin,str);
        getline(cin,str);
        str=" "+str+" ";
        for(string::size_type i=0;i!=str.size();i++)
        str[i]=toupper(str[i]);
        for(string::size_type i=str.find(word);i<str.size();
            i=str.find(word,i+word.size()-1),++ans)
        {   
            if(!ans)
            first=i;
        }
        if(ans)
        {
            cout<<ans<<" "<<first<<endl;
        }
        else cout<<"-1"<<endl;
        return 0;
        } 
    
    
    • 1

    Information

    ID
    18220
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By