-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.1.cpp
More file actions
65 lines (58 loc) · 1.47 KB
/
3.1.cpp
File metadata and controls
65 lines (58 loc) · 1.47 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
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
vector<string> ans;
vector<pair<string,string>> macros;
void catchmacros(vector<string> inp){
vector<string> all;
for(auto s : inp){
stringstream ss(s);
string word;
while (ss >> word) {
all.push_back(word);
}
}
for(int i = 0; i < (int)all.size()-2 ; i++){
if(all[i] == "#define"){
macros.push_back({all[i+1], all[i+2]});
}
}
}
void removemacros(vector<string> inp){
for(auto s : inp){
stringstream ss(s);
string word;
while (ss >> word) {
bool found = 0;
for(auto macr : macros){
if(macr.first == word.substr(0, (int)macr.first.size())){
cout << macr.second;
for(int j = (int)macr.first.size(); j < (int)word.size(); j++){
cout << word[j];
}
cout << " ";
found = 1;
break;
}
}
if(!found)
cout << word << ' ';
}
cout << '\n';
}
}
int main(){
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
string s;
bool single = 0, multi = 0;
vector<string> inp;
while(getline(cin,s)){
inp.push_back(s);
}
// removemacros(inp);
catchmacros(inp);
removemacros(inp);
for(auto i : ans){
cout << i << '\n';
}
}