-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.cpp
More file actions
54 lines (43 loc) · 1.03 KB
/
Copy pathsplit.cpp
File metadata and controls
54 lines (43 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//字符串分割函数
vector<string> split(string str, string pattern)
{
string::size_type pos;
vector<string> result;
str += pattern; //扩展字符串以方便操作
int size = str.size();
for (int i = 0; i < size; i++) {
pos = str.find(pattern, i);
if (pos < size) {
string s = str.substr(i, pos - i);
result.push_back(s);
i = pos + pattern.size() - 1;
}
}
return result;
}
int main()
{
int T;
cin >> T;
while (T --) {
int N, M;
cin >>N >> M;
string a[110], b[110];
for (int i = 0; i < M; i++) {
cin >> a[i] >> b[i];
}
string str;
getline(cin, str);
string pattern = " ";
cout << "str: " << str << endl;
vector<string> result = split(str, pattern);
for (int i = 0; i < result.size(); i++) {
cout << result[i] << endl;
}
}
return 0;
}