42 lines
609 B
C++
42 lines
609 B
C++
#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';
|
|
}
|