Last active
September 29, 2017 00:22
-
-
Save tyilo/d670cb304e72b7daed087ef9b492de03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#include <regex.h> | |
using namespace std; | |
#define rep(i, a, b) for (int i = a; i < (b); ++i) | |
#define trav(a, x) for (auto & a : x) | |
#define all(x) x.begin(), x.end() | |
#define sz(x) (int)(x).size() | |
typedef long long ll; | |
typedef pair<int, int> pii; | |
typedef vector<int> vi; | |
int main() { | |
cin.sync_with_stdio(0); cin.tie(0); | |
cin.exceptions(cin.failbit); | |
string P; | |
getline(cin, P); | |
string re; | |
trav(c, P) { | |
if (c == '*') { | |
re += ".*"; | |
} else if (c == '.') { | |
re += "\\."; | |
} else { | |
re += c; | |
} | |
} | |
re += '$'; | |
regex_t buf{}; | |
buf.fastmap = (char *)malloc(256); | |
if (re_compile_pattern(re.data(), sz(re), &buf)) { | |
return 1; | |
} | |
int n; | |
cin >> n; | |
string dummy; | |
getline(cin, dummy); | |
rep(i, 0, n) { | |
string S; | |
getline(cin, S); | |
int res = re_match(&buf, S.data(), sz(S), 0, nullptr); | |
if (res >= 0) { | |
cout << S << "\n"; | |
} | |
} | |
regfree(&buf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment