-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21.cpp
More file actions
34 lines (30 loc) · 1021 Bytes
/
21.cpp
File metadata and controls
34 lines (30 loc) · 1021 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
#include <fstream>
#include <iostream>
using namespace std;
vector<pair<int, int>> CreateCodeInstructions(const string & code) {
pair<int, int> currentPos;
vector<pair<int, int>> instructions;
for (int i = 0; i < code.length(); i++) {
auto targetPos = GetNrPos(code[i]);
pair<int, int> moveVector = {targetPos.first - currentPos.first, targetPos.second - currentPos.second};
instructions.push_back(moveVector);
currentPos = targetPos;
}
return instructions;
}
int Evaluate(const string & code) {
auto movements1 = CreateCodeInstructions(code);
auto movements2 = CreateMoveInstructions(movements1);
auto movements3 = CreateMoveInstructions(movements2);
auto movementsLength = CalculateLength(movements3);
return movementsLength * stoi(code.substr(0, code.length() - 1));
}
int main(){
ifstream in("Input.txt");
string lineTmp;
int sum = 0;
while (getline(in, lineTmp)) {
sum += Evaluate(lineTmp);
}
cout << sum;
}