Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- const ll MAXM = 4294967295;
- // Redo
- int main() {
- int n,m;
- cin>>n>>m;
- vector<string>s(n);
- int ct_s[n][5];
- for(int i=0;i<n;i++){
- cin>>s[i];
- }
- vector<string>p(m);
- for(int i=0;i<m;i++){
- cin>>p[i];
- int len=p[i].length();
- // vector<string>poss;
- vector<char>ch;
- vector<int>quest;
- ch={'a','b','c','d','e'};
- for(int j=0;j<len;j++){
- if(p[i][j]=='?') quest.push_back(j);
- }
- unordered_map<string,int>poss;
- int sz=quest.size();
- if(sz==1){
- for(int h=0;h<6;h++){
- vector<int>ques=quest;
- string str=p[i];
- if(h==5){
- str.erase(ques[0],1);
- }
- else{
- str[ques[0]]=ch[h];
- }
- poss[str]=1;
- }
- }
- // cout<<"exe after"<<endl;
- if(sz==2){
- for(int h=0;h<6;h++){
- for(int j=0;j<6;j++){
- vector<int>ques=quest;
- string str=p[i];
- if(h==5){
- str.erase(ques[0],1);
- // cout<<"exe deleted -"<<str<<" idx is - "<<ques[0]<<endl;
- ques[1]--;
- }
- else{
- str[ques[0]]=ch[h];
- }
- if(j==5){
- str.erase(ques[1],1);
- }
- else{
- str[ques[1]]=ch[j];
- }
- poss[str]=1;
- }
- }
- }
- if(sz==3){
- // for(auto val:quest){
- // cout<<val<<" ";
- // }
- // cout<<endl;
- for(int h=0;h<6;h++){
- for(int j=0;j<6;j++){
- for(int k=0;k<6;k++){
- vector<int>ques=quest;
- string str=p[i];
- if(h==5){
- str.erase(ques[0],1);
- ques[1]--;ques[2]--;
- }
- else{
- str[ques[0]]=ch[h];
- }
- if(j==5){
- str.erase(ques[1],1);
- ques[2]--;
- // cout<<"new ques2 :"<<ques[2]<<endl;
- }
- else{
- str[ques[1]]=ch[j];
- }
- if(k==5){
- str.erase(ques[2],1);
- }
- else{
- str[ques[2]]=ch[k];
- }
- // cout<<"str "<<i<<" "<<j<<" "<<k<<" "<<str<<endl;
- poss[str]=1;
- } //a?c?e?
- }
- }
- }
- // cout<<"exe "<<endl;
- // for(auto str:poss){
- // cout<<str<<endl;
- // }
- if(sz>=1){
- int match=0;
- for(int j=0;j<n;j++){
- if(poss[s[j]]==1){
- // cout<<s[j]<<" matched"<<endl;
- match++;
- }
- }
- cout<<match<<endl;
- }
- else{
- int match=0;
- for(int j=0;j<n;j++){
- if(s[j]==p[i]){
- match++;
- break;
- }
- }
- cout<<match<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment