|
发表于 2022-8-8 22:03:06
|
显示全部楼层
本帖最后由 人造人 于 2022-8-8 22:09 编辑
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <regex>
- using std::cin, std::cout, std::endl;
- using std::for_each, std::getline;
- using std::string, std::vector;
- using std::regex, std::smatch;
- using std::sregex_iterator;
- int main() {
- string word; getline(cin, word);
- string text; getline(cin, text);
- regex pattern("\\b" + word + "\\b", regex::icase);
- vector<smatch> result;
- for_each(sregex_iterator(text.begin(), text.end(), pattern), sregex_iterator(), [&result](const smatch &s) -> void {result.push_back(s);});
- if(!result.size()) cout << -1 << endl;
- else cout << result.size() << " " << result[0].position() << endl;
- return 0;
- }
复制代码 |
评分
-
查看全部评分
|