Advent 2022 day2 & day3
This commit is contained in:
parent
68a75987e2
commit
104f034568
6 changed files with 2923 additions and 0 deletions
26
advent_of_code_2022/day3/main1.cc
Normal file
26
advent_of_code_2022/day3/main1.cc
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
|
||||
int main()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::string packing;
|
||||
std::getline(std::cin, packing);
|
||||
|
||||
char double_packed{};
|
||||
std::set<char> c1{packing.begin(), packing.begin() + packing.size() / 2};
|
||||
std::set<char> c2{packing.begin() + packing.size() / 2, packing.end()};
|
||||
std::set_intersection(c1.begin(), c1.end(), c2.begin(), c2.end(), &double_packed);
|
||||
|
||||
result += std::islower(double_packed) ? (double_packed - 'a' + 1) : (double_packed - 'A' + 27);
|
||||
|
||||
if (std::cin.eof())
|
||||
break;
|
||||
}
|
||||
|
||||
fmt::print("Result: {}\n", result);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue