1 条题解

  • 0
    @ 2025-9-10 0:11:08

    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

    信息

    ID
    3003
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者