-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0022.cpp
More file actions
36 lines (33 loc) · 692 Bytes
/
0022.cpp
File metadata and controls
36 lines (33 loc) · 692 Bytes
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
#include <iostream>
#include <vector>
#include <functional>
#include <fstream>
#include <set>
#include <string>
void fn1() {
std::fstream in("names.txt");
// std::set is sorted
std::set<std::vector<int>> names;
while (!in.eof()) {
int c = in.get();
if (c == '"') {
std::vector<int> name;
while ((c = in.get()) != '"') {
name.push_back(c - '@'); // @ is A-1
}
names.insert(name);
}
}
int pos = 1;
int total = 0;
for (auto name: names) {
int sum = 0;
for (int c: name) {
sum += c;
}
total += (sum * pos);
pos++;
}
std::cout << total << std::endl;
}
std::vector<std::function<void()>> progs = { fn1 };