-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay5.cpp
More file actions
81 lines (76 loc) · 1.28 KB
/
Copy pathDay5.cpp
File metadata and controls
81 lines (76 loc) · 1.28 KB
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
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void getrow(char p,vector<int>&v)
{
if(p=='F')
{
v[0]=v[0];
v[1]=(v[0]+v[1])/2;
}
else if(p=='B')
{
v[0]=(v[0]+v[1]+1)/2;
v[1]=v[1];
}
}
void getcolumn(char p,vector<int>&v)
{
if(p=='R')
{
v[0] = (v[0] + v[1] + 1) / 2;
v[1] = v[1];
}
else if(p=='L')
{
v[0] = v[0];
v[1] = (v[0] + v[1]) / 2;
}
}
int getID(string str)
{
vector<int>v1;
vector<int>v2;
v2.push_back(0);
v2.push_back(7);
v1.push_back(0);
v1.push_back(127);
for(int a=0;a<7;a++)
{
getrow(str[a],v1);
}
for(int a=7;a<10;a++)
{
getcolumn(str[a],v2);
}
return v1[0]*8+v2[0];
}
int main()
{
vector<int> v;
fstream indata;
string p;
indata.open("Day5data");
if (indata.fail())
{
cout << "something is wrong";
}
while (indata)
{
getline(indata,p);
int l = getID(p);
v.push_back(l);
}
sort(v.begin(), v.end());
int k=v.size();
cout<<"part1:"<<v[k-1]<<endl;
for(int i=0;i<k;i++)
{
if(v[i+1]-v[i]==2)
{
cout<<"part2:"<<v[i+1]-1<<endl;
}
}
return 0;
}