题目原文请移步下面的链接
OI
、模拟
、字符串
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
void split(string &s, char a, vector<string> &vs) {
stringstream ss(s);
string item;
while (getline(ss, item, a)) {
vs.push_back(item);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string s;
cin >> s;
string str;
getline(cin, str);
int ans = 0;
int cnt = -1;
vector<string> vs;
getline(cin, str);
for(int i = 0; i < s.size(); i++) {
if ( s[i] <= 'Z' && s[i] >= 'A') {
s[i] += 32;
}
}
for(int i = 0; i < str.size(); i++) {
if ( str[i] <= 'Z' && str[i] >= 'A') {
str[i] += 32;
}
}
split(str, ' ', vs);
for (int i = 0; i < vs.size(); ++i) {
if (vs[i] == s) {
ans++;
}
if (ans == 0) {
cnt += vs[i].size() + 1;
} else if (ans == 1 && i == 0) {
cnt = 0;
}
}
if (ans == 0) {
cout << -1;
} else if (cnt == 0) {
cout << ans << " " << cnt;
} else {
cout << ans << " " << cnt + 1;
}
return 0;
}