-
Notifications
You must be signed in to change notification settings - Fork 13
/
cgs-minifier.cpp
39 lines (35 loc) · 1.03 KB
/
cgs-minifier.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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
string in, out, tmp;
char repl = '`';
int main() {
map<string, char> repl_map;
int N; cin >> N; cin.ignore();
for (int i = 0; i < N && getline(cin, tmp); i++) { in += tmp; }
for (int i = 0; i < in.size(); i++) {
char c = in[i];
if ( c == '$' ) {
string t;
out.push_back(c);
do { i++; t.push_back(in[i]); } while( in[i] != '$' );
if(repl_map.find(t) == repl_map.end()) {repl_map[t] = ++repl;}
out.push_back(repl_map[t]);
out.push_back(c);
}
else if ( c == '\'' ) {
out.push_back(c);
do { i++; out.push_back(in[i]); } while( in[i] != '\'' );
}
else {
switch(in[i]) {
case ' ' : case '\t': case '\n': break;
default : out.push_back(in[i]); break;
}
}
}
cout << out << endl;
}