-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 8 Part 2.cpp
70 lines (67 loc) · 1.61 KB
/
Day 8 Part 2.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
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
66
67
68
69
70
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <sstream>
#include <utility>
#include <cctype>
#include <set>
#include <stack>
void column_rotate(std::vector<std::vector<int>>& screen, int column, int amount);
int main()
{
std::ifstream fin("file.txt");
std::string line;
std::vector<std::vector<int>> screen(6, std::vector<int>(50, 0));
while (std::getline(fin, line))
{
std::string command, row_or_column;
int row_or_column_number, value;
std::stringstream ss(line);
ss >> command;
if (command == "rect")
{
int x, y;
char eater;
ss >> x >> eater >> y;
for (int i = 0; i < y; ++i)
for (int j = 0; j < x; ++j)
screen[i][j] = 1;
}
else
{
char eater;
ss >> row_or_column >> eater >> eater >> row_or_column_number >> eater >> eater >> value;
if (row_or_column == "row")
{
auto& row = screen[row_or_column_number];
std::rotate(row.rbegin(), row.rbegin() + value, row.rend());
}
else
{
column_rotate(screen, row_or_column_number, value);
}
}
}
int counter = 0;
for (int i = 0; i < 6; ++i)
{
for (int j = 0; j < 50; ++j)
{
if (j && j % 5 == 0)
std::cout << " ";
std::cout << (screen[i][j] ? 'X' : ' ');
}
std::cout << "\n";
}
}
void column_rotate(std::vector<std::vector<int>>& screen, int column, int amount)
{
std::vector<int> col;
for (int i = 0; i < 6; i++)
col.push_back(screen[i][column]);
std::rotate(col.rbegin(), col.rbegin() + amount, col.rend());
for (int i = 0; i < 6; i++)
screen[i][column] = col[i];
}