-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbili3.cpp
47 lines (40 loc) · 877 Bytes
/
bili3.cpp
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
#include <iostream>
#include <vector>
#include <sstream>
#include <cassert>
using namespace std;
struct Map
{
string key;
string val;
Map(const string& k, const string& v)
: key(k), val(v) {}
void Printer() { cout << key << ' ' << val << endl; }
};
int main()
{
string pdeli, kvdeli, input;
cin >> pdeli >> kvdeli >> input;
assert(pdeli.size() == 1);
assert(kvdeli.size() == 1);
int count = 0;
vector<Map> kvs;
istringstream is(input);
for (string pair; std::getline(is, pair, pdeli[0]);)
{
size_t pos = pair.find(kvdeli);
if (pos != string::npos)
{
string key = pair.substr(0, pos);
string val = pair.substr(pos + 1);
if (!key.empty() && !val.empty())
{
++count;
kvs.emplace_back(key, val);
}
}
}
cout << count << endl;
for (auto &e : kvs) e.Printer();
return 0;
}