Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //abcdefghrtyu
- //*jxeqql
- //jxeqql
- using namespace std;
- string g, temp, without, first, second, s, ans;
- bool pr[500], was, as = 0;
- string fix = "";
- int n, point = 1000000;
- int main(){
- cin >> g >> temp >> n;
- for(int i = 0; i < g.size(); i++){
- pr[g[i]] = 1;
- }
- for(int i = 0; i < temp.size(); i++){
- if(temp[i] == '*'){
- point = i;
- was = 1;
- }
- if(!was)
- first += temp[i];
- else
- second += temp[i];
- }
- without = "";
- for(int i = point + 1; i < temp.size(); i++){
- without += temp[i];
- }
- for(int i = 0; i < n; i++){
- cin >> s;
- fix = "";
- string fixx = "";
- //cout << "newest" << endl;
- ans = "YES";
- if(s.size() < temp.size() - 1 && was){
- //cout << 1 << endl;
- ans = "NO";
- }
- else{
- for(int j = 0; j < first.size(); j++){
- if(first[j] == s[j])
- fix += s[j];
- else if(first[j] == '?' && pr[s[j]])
- fix += s[j];
- else{
- //cout << 2 << endl;
- ans = "NO";
- break;
- }
- }
- if(ans != "NO" && was){
- if(s.size() == temp.size() - 1 && was){
- for(int j = point + 1; j < temp.size(); j++){
- if(temp[j] == s[j - 1]){
- fixx += temp[j];
- }
- else if(temp[j] == '?' && pr[s[j-1]]){
- fixx += s[j - 1];
- }
- else{
- //cout << 6 << endl;
- ans = "NO";
- break;
- }
- }
- if(fix + fixx == s){
- //cout << 3 << endl;
- as = 1;
- }
- else
- ans = "NO";
- }
- int dif = (int)s.size() - (int)temp.size();
- if(ans != "NO"){
- for(int j = point; j <= point + dif; j++){
- if(!pr[s[j]]){
- con += s[j];
- }
- else{
- con += '9';
- }
- }
- }
- for(int j = point + dif + 1; j < s.size(); j++){
- if(s[j] == temp[j - dif]){
- con += s[j];
- }
- else if(temp[j] == '?' && pr[s[j]])
- con += s[j];
- else{
- //cout << 5 << endl;
- ans = "NO";
- break;
- }
- }
- }
- }
- if(as == 1){
- ans = "YES";
- }
- cout << ans << endl;
- as = 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement