mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:31:59 +00:00
P1308 统计单词数
R38659937
This commit is contained in:
parent
6287bdaaa6
commit
a2a33e62da
41
problem/P1308/P1308.cpp
Normal file
41
problem/P1308/P1308.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
// https://www.luogu.com.cn/record/38659937
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int cnt = 0, t = 0;
|
||||
string word, p;
|
||||
|
||||
getline(cin, word);
|
||||
getline(cin, p);
|
||||
|
||||
for (int i = 0; i < word.size(); i++) {
|
||||
if ('a' <= word[i] && word[i] <= 'z') {
|
||||
word[i] -= 32;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < p.size(); i++) {
|
||||
if ('a' <= p[i] && p[i] <= 'z') {
|
||||
p[i] -= 32;
|
||||
}
|
||||
}
|
||||
|
||||
word = ' ' + word + ' ';
|
||||
p = ' ' + p + ' ';
|
||||
|
||||
if (p.find(word) == string::npos) {
|
||||
cout << -1 << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (t != string::npos) {
|
||||
cnt++;
|
||||
t = p.find(word, t + 1);
|
||||
}
|
||||
|
||||
cout << --cnt << ' ' << p.find(word) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user