使用string.find()可以暴力破解
#include <iostream>
#include <string>
using namespace std;
struct Node
{
string m;
string p;
};
int main()
{
int n;
cin >> n;
Node str[100];
for (int i = 0;i < n;i++)
{
Node temp;
cin >> temp.m >> temp.p;
str[i] = temp;
}
for (int i = 0;i < n;i++)
{
int len = str[i].m.size() - str[i].p.size()+1;
for (int j = 0;j < len;j++)
{
int loc = str[i].m.find(str[i].p,j);
if (loc != str[i].m.npos)
{
cout << loc << ' ' ;
j = loc;
}
}
cout << endl;
}
}