求助!!这个查找位置应该怎么改?
查看原帖
求助!!这个查找位置应该怎么改?
1128181
Evolution333楼主2023/11/5 20:39
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string a,b;
    string tmp;
    size_t pos = 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);
        cout<<cnt<<' '<<pos;
    }
    else cout<<-1;


    return 0;

}
2023/11/5 20:39
加载中...