Advertisement
askarulytarlan

Untitled

Jul 26th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. //abcdefghrtyu
  3. //*jxeqql
  4.  
  5. //jxeqql
  6.  
  7. using namespace std;
  8. string g, temp, without, first, second, s, ans;
  9. bool pr[500], was, as = 0;
  10. string fix = "";
  11. int n, point = 1000000;
  12. int main(){
  13. cin >> g >> temp >> n;
  14. for(int i = 0; i < g.size(); i++){
  15. pr[g[i]] = 1;
  16. }
  17. for(int i = 0; i < temp.size(); i++){
  18. if(temp[i] == '*'){
  19. point = i;
  20. was = 1;
  21. }
  22. if(!was)
  23. first += temp[i];
  24. else
  25. second += temp[i];
  26. }
  27. without = "";
  28. for(int i = point + 1; i < temp.size(); i++){
  29. without += temp[i];
  30. }
  31. for(int i = 0; i < n; i++){
  32. cin >> s;
  33. fix = "";
  34. string fixx = "";
  35. //cout << "newest" << endl;
  36. ans = "YES";
  37. if(s.size() < temp.size() - 1 && was){
  38. //cout << 1 << endl;
  39. ans = "NO";
  40. }
  41. else{
  42.  
  43. for(int j = 0; j < first.size(); j++){
  44. if(first[j] == s[j])
  45. fix += s[j];
  46. else if(first[j] == '?' && pr[s[j]])
  47. fix += s[j];
  48. else{
  49. //cout << 2 << endl;
  50. ans = "NO";
  51. break;
  52. }
  53. }
  54. if(ans != "NO" && was){
  55.  
  56. if(s.size() == temp.size() - 1 && was){
  57. for(int j = point + 1; j < temp.size(); j++){
  58. if(temp[j] == s[j - 1]){
  59. fixx += temp[j];
  60. }
  61. else if(temp[j] == '?' && pr[s[j-1]]){
  62. fixx += s[j - 1];
  63. }
  64. else{
  65. //cout << 6 << endl;
  66. ans = "NO";
  67. break;
  68. }
  69. }
  70. if(fix + fixx == s){
  71. //cout << 3 << endl;
  72. as = 1;
  73. }
  74. else
  75. ans = "NO";
  76. }
  77.  
  78. int dif = (int)s.size() - (int)temp.size();
  79. if(ans != "NO"){
  80.  
  81. for(int j = point; j <= point + dif; j++){
  82. if(!pr[s[j]]){
  83. con += s[j];
  84. }
  85. else{
  86. con += '9';
  87. }
  88. }
  89. }
  90.  
  91. for(int j = point + dif + 1; j < s.size(); j++){
  92. if(s[j] == temp[j - dif]){
  93. con += s[j];
  94. }
  95. else if(temp[j] == '?' && pr[s[j]])
  96. con += s[j];
  97. else{
  98. //cout << 5 << endl;
  99. ans = "NO";
  100. break;
  101. }
  102. }
  103.  
  104. }
  105.  
  106. }
  107. if(as == 1){
  108. ans = "YES";
  109. }
  110. cout << ans << endl;
  111. as = 0;
  112. }
  113.  
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement