include<iostream>
include<string>
using namespace std;
int main()
{
string model;
string check;
getline(cin, model);
model.erase(model.size() - 2); //去掉输入里的“ #”
while (getline(cin,check))
{
check.erase(check.size() - 2); //去掉子串里的” #“
int pos = model.rfind(check);
if (pos == -1)
{
cout << -1 << endl;
continue;
}
int word = 1;
for (int i = pos; i != 0; i--)
if (model[i] == ' ')
word++;
cout << word << endl;
}
}
《NOJ1029 短语搜索》有1个想法