Day 13
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
using namespace std;
|
||||
|
||||
set<pair<int,int>> flip_about(set<pair<int,int>> input_points, bool x_flip, int value);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string line;
|
||||
bool coord_input = true;
|
||||
set<pair<int,int>> coords;
|
||||
vector<pair<bool,int>> folds;
|
||||
while(getline(cin, line))
|
||||
{
|
||||
if (0 == line.size())
|
||||
{
|
||||
coord_input = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (coord_input)
|
||||
{
|
||||
string::size_type n = line.find(',');
|
||||
pair<int,int> coord(stoi(line.substr(0,n)), stoi(line.substr(n+1)));
|
||||
coords.insert(coord);
|
||||
}
|
||||
else
|
||||
{
|
||||
string::size_type n = line.find_last_of(' ');
|
||||
line = line.substr(n+1);
|
||||
pair<bool,int> fold(line[0]=='x', stoi(line.substr(2)));
|
||||
folds.push_back(fold);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
coords = flip_about(coords, folds[0].first, folds[0].second);
|
||||
|
||||
cout << coords.size() << endl;
|
||||
}
|
||||
|
||||
set<pair<int,int>> flip_about(set<pair<int,int>> input_points, bool x_flip, int value)
|
||||
{
|
||||
set<pair<int,int>> output_points;
|
||||
set<pair<int,int>>::iterator it = input_points.begin();
|
||||
for(; it != input_points.end(); ++it)
|
||||
{
|
||||
if (x_flip)
|
||||
{
|
||||
if (it->first > value)
|
||||
{
|
||||
pair<int,int> flipped_coord(2*value-it->first, it->second);
|
||||
output_points.insert(flipped_coord);
|
||||
}
|
||||
else
|
||||
{
|
||||
output_points.insert(*it);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (it->second > value)
|
||||
{
|
||||
pair<int,int> flipped_coord(it->first, 2*value-it->second);
|
||||
output_points.insert(flipped_coord);
|
||||
}
|
||||
else
|
||||
{
|
||||
output_points.insert(*it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output_points;
|
||||
}
|
||||
Reference in New Issue
Block a user