-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpa_lab_4_5_7_(8)-B.cpp
47 lines (40 loc) · 1.27 KB
/
cpa_lab_4_5_7_(8)-B.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>
using namespace std;
void takeFirstElementSeparatedByComma(string &values, int commaIndex, vector<string> &key, vector<string> &value)
{
string substring;
int equalIndex;
substring = values.substr(0,commaIndex);
equalIndex = substring.find("=");
key.push_back("[" + substring.substr(0, equalIndex) + "]");
value.push_back(substring.substr(equalIndex + 1));
values.erase(0, commaIndex + 1);
}
int main()
{
string values;
vector<string> key, value;
getline(cin, values);
string mytemplate;
getline(cin, mytemplate);
int commaIndex = values.find(",");
int regexIndex;
while(commaIndex != -1) //Take all keys and values before each comma
{
takeFirstElementSeparatedByComma(values, commaIndex, key, value);
commaIndex = values.find(",");
}
takeFirstElementSeparatedByComma(values, values.length(), key, value); //take last key and value, after all commas
for(int i = 0; i < key.size(); ++i)
{
regexIndex = mytemplate.find(key[i]);
while(regexIndex != -1)
{
mytemplate.replace(regexIndex, key[i].length(), value[i]);
regexIndex = mytemplate.find(key[i]);
}
}
cout << mytemplate << "\n";
return 0;
}