advent-of-code/2024/19/main-1.cpp

42 lines
609 B
C++
Raw Permalink Normal View History

2024-12-18 21:41:33 -08:00
#include "../../include/aoc.hpp"
#include <bits/stdc++.h>
using namespace std;
vector<string> towels;
bool rec(string_view s) {
if (s.empty()) {
return true;
}
for (auto &t : towels) {
if (s.starts_with(t) && rec(s.substr(t.size()))) {
return true;
}
}
return false;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string line;
getline(cin, line);
istringstream ll(line);
string s;
while (getline(ll, s, ',')) {
towels.push_back(s);
ll.ignore();
}
cin.ignore();
ull count = 0;
while (getline(cin, line)) {
if (rec(line)) {
count++;
}
}
cout << count << '\n';
}