求助!!80
查看原帖
求助!!80
1128181
Evolution333楼主2023/11/5 21:26
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string a,b;
    string tmp;
    size_t pos = 0;
    size_t posnext = 0;
    int cnt = 0;


    getline(cin,a);
    getline(cin,b);

    transform(a.begin(),a.end(),a.begin(),::tolower);
    transform(b.begin(),b.end(),b.begin(),::tolower);





    stringstream ssin(b);

    while (ssin>>tmp)
    {
        if(tmp==a) cnt++;
    }


    if(cnt) {
       pos = b.find(a);

       if(a.size()==1) {
           while (!(b[pos + 1] == ' ' && b[pos - 1] == ' ') && (pos + 1 < b.size() && pos - 1 >= 0)) {
               pos = b.find(a, pos + 1);
           }
       }

        cout<<cnt<<' '<<pos;
    }
    else cout<<-1;


    return 0;

}
2023/11/5 21:26
加载中...