rishmish0806

Untitled

May 22nd, 2025
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. const ll MAXM = 4294967295;
  5. // Redo
  6. int main() {
  7. int n,m;
  8. cin>>n>>m;
  9.  
  10. vector<string>s(n);
  11. int ct_s[n][5];
  12. for(int i=0;i<n;i++){
  13. cin>>s[i];
  14.  
  15. }
  16.  
  17. vector<string>p(m);
  18. for(int i=0;i<m;i++){
  19. cin>>p[i];
  20. int len=p[i].length();
  21. // vector<string>poss;
  22. vector<char>ch;
  23. vector<int>quest;
  24. ch={'a','b','c','d','e'};
  25. for(int j=0;j<len;j++){
  26. if(p[i][j]=='?') quest.push_back(j);
  27. }
  28. unordered_map<string,int>poss;
  29. int sz=quest.size();
  30. if(sz==1){
  31.  
  32. for(int h=0;h<6;h++){
  33. vector<int>ques=quest;
  34. string str=p[i];
  35. if(h==5){
  36. str.erase(ques[0],1);
  37. }
  38. else{
  39. str[ques[0]]=ch[h];
  40. }
  41.  
  42. poss[str]=1;
  43.  
  44. }
  45. }
  46. // cout<<"exe after"<<endl;
  47.  
  48. if(sz==2){
  49.  
  50. for(int h=0;h<6;h++){
  51. for(int j=0;j<6;j++){
  52. vector<int>ques=quest;
  53. string str=p[i];
  54. if(h==5){
  55. str.erase(ques[0],1);
  56. // cout<<"exe deleted -"<<str<<" idx is - "<<ques[0]<<endl;
  57. ques[1]--;
  58. }
  59. else{
  60. str[ques[0]]=ch[h];
  61. }
  62. if(j==5){
  63. str.erase(ques[1],1);
  64. }
  65. else{
  66.  
  67. str[ques[1]]=ch[j];
  68. }
  69.  
  70. poss[str]=1;
  71.  
  72.  
  73.  
  74. }
  75. }
  76. }
  77.  
  78. if(sz==3){
  79. // for(auto val:quest){
  80. // cout<<val<<" ";
  81. // }
  82. // cout<<endl;
  83. for(int h=0;h<6;h++){
  84. for(int j=0;j<6;j++){
  85. for(int k=0;k<6;k++){
  86. vector<int>ques=quest;
  87. string str=p[i];
  88. if(h==5){
  89. str.erase(ques[0],1);
  90. ques[1]--;ques[2]--;
  91. }
  92. else{
  93. str[ques[0]]=ch[h];
  94.  
  95. }
  96. if(j==5){
  97. str.erase(ques[1],1);
  98. ques[2]--;
  99. // cout<<"new ques2 :"<<ques[2]<<endl;
  100.  
  101. }
  102. else{
  103. str[ques[1]]=ch[j];
  104.  
  105. }
  106.  
  107. if(k==5){
  108. str.erase(ques[2],1);
  109. }
  110. else{
  111. str[ques[2]]=ch[k];
  112. }
  113. // cout<<"str "<<i<<" "<<j<<" "<<k<<" "<<str<<endl;
  114.  
  115. poss[str]=1;
  116.  
  117.  
  118. } //a?c?e?
  119. }
  120. }
  121. }
  122. // cout<<"exe "<<endl;
  123. // for(auto str:poss){
  124. // cout<<str<<endl;
  125. // }
  126. if(sz>=1){
  127. int match=0;
  128. for(int j=0;j<n;j++){
  129. if(poss[s[j]]==1){
  130. // cout<<s[j]<<" matched"<<endl;
  131. match++;
  132. }
  133. }
  134.  
  135. cout<<match<<endl;
  136. }
  137.  
  138. else{
  139. int match=0;
  140. for(int j=0;j<n;j++){
  141. if(s[j]==p[i]){
  142. match++;
  143. break;
  144. }
  145. }
  146. cout<<match<<endl;
  147. }
  148.  
  149.  
  150.  
  151.  
  152. }
  153.  
  154.  
  155. return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment