Skip to content

Commit 9c36c15

Browse files
committed
21-07-23 backup
1 parent fa6757b commit 9c36c15

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

huawei/3.exam.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*************************************************************************
2+
> File Name: 3.exam.cpp
3+
> Author: Cui Guochong
4+
5+
> Created Time: Thu 22 Jul 2021 10:16:56 AM CST
6+
************************************************************************/
7+
8+
#include <iostream>
9+
#include <string>
10+
#include <vector>
11+
#include <algorithm>
12+
using namespace std;
13+
14+
struct CMP {
15+
bool operator()(pair<int, int> &a, pair<int, int> &b) {
16+
return a.first < b.first;
17+
}
18+
};
19+
20+
string func(string &s, vector<string> &dict) {
21+
vector<pair<int, int>> location;
22+
for (string str : dict) {
23+
int start = s.find(str);
24+
int end = start + str.size() - 1;
25+
location.push_back({start, end});
26+
}
27+
sort(location.begin(), location.end(), CMP());
28+
vector<pair<int, int>> final_location;
29+
int start_pre = location[0].first, end_pre = location[0].second;
30+
for (int i = 1; i < location.size(); i++) {
31+
if (location[i].first <= end_pre + 1) {
32+
end_pre = location[i].second;
33+
continue;
34+
}
35+
final_location.push_back({start_pre, end_pre});
36+
start_pre = location[i].first;
37+
end_pre = location[i].second;
38+
}
39+
final_location.push_back({start_pre, end_pre});
40+
cout << location.size() << " " << final_location.size() << endl;
41+
string ret = "";
42+
int location_pre = 0;
43+
for (auto fl : final_location) {
44+
ret += s.substr(location_pre, fl.first - location_pre);
45+
ret += "<b>";
46+
ret += s.substr(fl.first, fl.second - fl.first + 1);
47+
ret += "</b>";
48+
location_pre = fl.second + 1;
49+
}
50+
if (location_pre < s.size()) {
51+
ret += s.substr(location_pre, s.size() - location_pre);
52+
}
53+
return ret;
54+
}
55+
56+
int main() {
57+
string s;
58+
cin >> s;
59+
vector<string> dict;
60+
string str;
61+
while (cin >> str) {
62+
dict.push_back(str);
63+
}
64+
cout << func(s, dict) << endl;
65+
return 0;
66+
}

huawei/a.out

54.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)