-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask14a.cpp
More file actions
56 lines (50 loc) · 1.72 KB
/
task14a.cpp
File metadata and controls
56 lines (50 loc) · 1.72 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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
string line;
getline(cin, line);
list<pair<char, bool>> polymer;
for (int i = 0; i < line.size(); ++i) {
polymer.push_back(make_pair(line[i], true));
}
char first, second, insert;
vector<tuple<char, char, char>> inserts;
while (getline(cin, line)) {
if (line.find("->") != string::npos) {
first = line[0];
second = line[1];
insert = line.back();
inserts.push_back(make_tuple(first, second, insert));
// cout << first << ' ' << second << ' ' << insert << '\n';
}
}
for (int i = 0; i < 10; ++i) {
for (auto &[first, second, insert]: inserts) {
for (auto it = polymer.begin(); it != polymer.end(); ++it) {
if ((*it).first == first && (*it).second && (*next(it)).first == second && (*next(it)).second) {
// cout << (*it).first << ' ' << (*next(it)).first << ' ' << insert << '\n';
polymer.insert(next(it), make_pair(insert, false));
}
}
}
for (auto it = polymer.begin(); it != polymer.end(); ++it) {
(*it).second = true;
// cout << (*it).first;
}
// cout << '\n';
}
// cout << polymer.size() << '\n';
unordered_map<char, int> count;
int maxCount = 0, minCount = 1e9;
for (auto &[c, b] : polymer) {
count[c]++;
}
for (auto &[k, v] : count) {
cout << k << ' ' << v << '\n';
maxCount = max(maxCount, v);
minCount = min(minCount, v);
}
cout << maxCount - minCount;
return 0;
}