Added older advents
This commit is contained in:
parent
8db2505049
commit
9cf858b860
78 changed files with 13807 additions and 0 deletions
54
advent_of_code_2015/day6/main.ih
Normal file
54
advent_of_code_2015/day6/main.ih
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum Action
|
||||
{
|
||||
TURN_OFF,
|
||||
TURN_ON,
|
||||
TOGGLE
|
||||
};
|
||||
|
||||
struct Point
|
||||
{
|
||||
size_t x;
|
||||
size_t y;
|
||||
|
||||
Point()
|
||||
: x(0), y(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
struct Instruction
|
||||
{
|
||||
Action action;
|
||||
Point from;
|
||||
Point through;
|
||||
};
|
||||
|
||||
istream &operator>>(istream &in, Point &point)
|
||||
{
|
||||
cin >> point.x;
|
||||
cin.ignore(1); // ignore ','
|
||||
cin >> point.y;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
// thrash tier parsing function
|
||||
istream &operator>>(istream &in, Instruction &instruction)
|
||||
{
|
||||
cin.ignore(5);
|
||||
string command;
|
||||
cin >> command;
|
||||
if (command == "le")
|
||||
instruction.action = TOGGLE;
|
||||
else instruction.action = command == "on" ? TURN_ON : TURN_OFF;
|
||||
cin >> instruction.from;
|
||||
cin.ignore(9); //ignore ' through '
|
||||
cin >> instruction.through;
|
||||
|
||||
return in;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue