1
0
Fork 0
Advent2022/Day3/part1.cpp

36 lines
769 B
C++

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
int total = 0;
string line;
while(getline(cin, line))
{
string half1 = line.substr(0, line.size()/2);
string half2 = line.substr(line.size()/2);
sort(half1.begin(), half1.end());
sort(half2.begin(), half2.end());
string remaining;
set_intersection(half1.begin(), half1.end(), half2.begin(), half2.end(), back_inserter(remaining));
int value;
if (remaining[0] >= 'a')
{
value = remaining[0]-'a'+1;
}
else
{
value = remaining[0]-'A'+27;
}
total += value;
}
cout << total << endl;
}