以下是代码
#include <bits/stdc++.h>
using namespace std;
string word, article;
int ans, ansxy;
bool flag = false;
int main() {
getline(cin, word);
getline(cin, article);
for (int i = 0; i <= word.size(); i++)
if (word[i] >= 'A' && word[i] <= 'Z')
word[i] += 'a' - 'A';
for (int i = 0; i <= article.size(); i++)
if (article[i] >= 'A' && article[i] <= 'Z')
article[i] += 'a' - 'A';
int st = -1, ed = -1;
for (int i = 0; i <= article.size(); i++) {
st = ed;
while (article[i] != ' ' && article[i] != '\n')
i++;
ed = i;
string temp = article.substr(st + 1, ed - st - 1);
if (temp == word) {
ans++;
if (!flag) {
ansxy = st + 1;
flag = true;
}
}
}
if (flag)
cout << ans << " " << ansxy;
else
cout << "-1";
return 0;
}