#include #include #include #include #include #include #include typedef unsigned long long int ulli; ulli fact(int n, std::vector& factCache) { ulli lastFact = factCache[factCache.size() - 1]; if (factCache.size() > n) { return factCache[n]; } for (int i = factCache.size(); i <= n; ++i) { factCache.push_back(lastFact * i); lastFact *= i; } return factCache[n]; } ulli binomial(int n, int k, std::vector& factCache) { return (fact(n, factCache)) / ((fact(k, factCache)) * (fact((n-k), factCache))); } struct binomialNum { std::pair duo; ulli val; bool operator <(const binomialNum& other) const { return val < other.val; } }; int solve(std::vector& cache) { int input; std::cin >> input; if (input == 1) return 1; std::priority_queue, std::less<>> q; std::set map; binomialNum first = {std::make_pair(2, 1), 2 }; q.push(first ); map.insert(first); while (!q.empty()) { binomialNum current = q.top(); map.insert(current); ulli left = ((current.val) * current.duo.second)/(current.duo.first - current.duo.second + 1); ulli right = (current.val) * ((current.duo.first - current.duo.second)/(current.duo.second + 1)); ulli aVal = left + current.val; ulli bVal = right + current.val; std::cout << current.duo.first << " nad " << current.duo.second << " = " << current.val << std::endl; binomialNum nextA = {std::make_pair(current.duo.first + 1, current.duo.second), aVal}; binomialNum nextB = {std::make_pair(current.duo.first + 1, current.duo.second + 1), bVal}; if (aVal == input || bVal == input) return nextA.duo.first + 1; bool containsA = map.find(nextA) != map.end(); bool containsB = map.find(nextB) != map.end(); q.pop(); if (aVal == bVal) { if (aVal < input && !containsA) { q.push(nextA); } } else { if (aVal < input && !containsA) { q.push(nextA); } if (bVal < input && !containsB) { q.push(nextB); } } } return -1; } void regex() { std::string *undamaged; int undamagedSize; // Get undamaged numbers (TODO: Leading zeroes) std::cin >> undamagedSize; undamaged = new std::string[undamagedSize]; for(int i = 0; i < undamagedSize; i++) std::cin >> undamaged[i]; int size; std::cin >> size; // Check each damaged number std::string read_damaged; for(int i = 0; i < size; i++) { std::string damaged = ""; std::cin >> read_damaged; for(char c : read_damaged) { if(c == '?') damaged += "."; else if(c == '*') damaged += ".*"; else damaged += c; } int count = 0; std::regex reg(damaged); for(int i = 0; i < undamagedSize; i++) { if(std::regex_match(undamaged[i], reg)) count++; } std::cout << count << std::endl; } delete[] undamaged; } int main() { regex(); return 0; //std::regex reg("a.*"); //std::string a = "bbc"; //std:: cout << (std::regex_match(a, reg) ? "true" : "false" ) << std::endl; std::vector factCache; factCache.push_back(1); factCache.push_back(1); int input; std::cin >> input; for (int i = 0; i < input; ++i) { std::cout << solve(factCache) << std::endl; } return 0; }