'commit'
This commit is contained in:
32
TangDou/CSP-J/AcWingTraining/T3/446.cpp
Normal file
32
TangDou/CSP-J/AcWingTraining/T3/446.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
string p, s;
|
||||
|
||||
void to_lower(string &s) {
|
||||
for (auto &c : s) c = tolower(c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
getline(cin, p);
|
||||
getline(cin, s);
|
||||
to_lower(p), to_lower(s);
|
||||
|
||||
int cnt = 0, k = -1;
|
||||
for (int i = 0; i < s.size(); i++) {
|
||||
if (s[i] == ' ') continue;
|
||||
int j = i + 1;
|
||||
while (j < s.size() && s[j] != ' ') j++; // 找到结束位置
|
||||
if (p == s.substr(i, j - i)) { // 截取并判断是不是相等
|
||||
cnt++;
|
||||
if (k == -1) k = i;
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
|
||||
if (!cnt)
|
||||
puts("-1");
|
||||
else
|
||||
cout << cnt << ' ' << k << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user