-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrucksack2.cpp
More file actions
91 lines (86 loc) · 1.9 KB
/
rucksack2.cpp
File metadata and controls
91 lines (86 loc) · 1.9 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
82
83
84
85
86
87
88
89
90
91
#include <bits/utility.h>
#include <cctype>
#include <cstddef>
#include <fstream>
#include <ios>
#include <iostream>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
void strSearch(std::string s1, std::string s2, std::string s3, char &letter)
{
std::string temp{""};
for (int i{0}; i < s1.length(); ++i)
{
for (int j{0}; j < s2.length() + 1; ++j)
{
if (s1[i] == s2[j])
{
temp += s2[j];
}
}
}
for (int k{0}; k < temp.length(); ++k)
{
for (int l{0}; l < s3.length(); ++l)
{
if (temp[k] == s3[l])
{
letter = s3[l];
}
}
}
}
void letterVals(char c, int &x)
{
char start = 'A';
for (size_t i{0}; i < 58; ++i)
{
if (c == start && start > 96)
{
x = start - 96;
break;
}
else if (c == start && start < 97)
{
x = start - 38;
break;
}
++start;
}
}
int main()
{
std::string s, testStr1{""}, testStr2{""}, testStr3{""};
std::ifstream infile("day3.txt", std::ios::in);
char common;
int length, letterValue, count{0}, sum{0};
std::cout << "working...\n";
while (std::getline(infile, s))
{
switch (count) {
case 0:
testStr1 = s;
++count;
break;
case 1:
testStr2 = s;
++count;
break;
case 2:
testStr3 = s;
++count;
break;
}
if (count == 3)
{
strSearch(testStr1, testStr2, testStr3, common);
letterVals(common, letterValue);
sum += letterValue;
count = 0;
}
}
std::cout << "Part 2: " << sum << std::endl;
return 0;
}