Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<vector>
  4.  
  5.  
  6. /* 효율성 테스트3 실패(5.98ms, 15.1MB)
  7. int find_word(std::string queries, std::vector<std::string> &word) {
  8. std::string temp_word;
  9. int find_num = 0;
  10. bool flag = 1;
  11. for (int i = 0; i < word.size(); i++) {
  12. int fir, end;
  13. if (word[i].size() == queries.length()) {
  14. temp_word = word[i];
  15. flag = 0;
  16. if (queries[0] == '?') {
  17. fir = queries.find_first_not_of('?');
  18. end = queries.length() - fir;
  19. temp_word = temp_word.substr(fir, end);
  20. if (queries.compare(fir, end, temp_word) == 0) {
  21. flag = 1;
  22. }
  23. }
  24. else {
  25. end = queries.find_first_of('?');
  26. temp_word = temp_word.substr(0, end);
  27. if (!queries.compare(0, end, temp_word)) {
  28. flag = 1;
  29. }
  30. }
  31. if (flag) {
  32. find_num++;
  33. }
  34. }
  35. }
  36. return find_num;
  37. }
  38.  
  39. int main() {
  40. std::vector <std::string> word{ "frodo", "front","frost","frozen","frame","kakao" };
  41. std::vector <std::string> queries{ "fro??","????o","fr???","fro???","pro?" };
  42.  
  43. for (int i = 0; i < queries.size(); i++) {
  44. std::vector<std::string> word2 = word;
  45.  
  46. for (int k = 0; k < word2.size(); k++) {
  47. if (word2[k].length() != queries[i].length()) {
  48.  
  49. word2.erase(word2.begin()+k);
  50. k--;
  51. }
  52. }
  53. printf("%d\n", find_word(queries[i], word2));
  54. }
  55. return 0;
  56. }
  57.  
  58. */
  59.  
  60. /* 효율성 테스트3 실패 (5.78ms, 12.9MB)
  61. int find_word(std::string queries, std::vector<std::string> &word) {
  62. std::string temp_word;
  63. int find_num = 0;
  64. bool flag = 1;
  65. for (int i = 0; i < word.size(); i++) {
  66. int fir,end;
  67. if (word[i].size() == queries.length()) {
  68. temp_word = word[i];
  69. flag = 0;
  70. if (queries[0] == '?') {
  71. fir = queries.find_first_not_of('?');
  72. end = queries.length() - fir;
  73. temp_word = temp_word.substr(fir, end);
  74. if (queries.compare(fir, end, temp_word)==0) {
  75. flag = 1;
  76. }
  77. }
  78. else {
  79. end=queries.find_first_of('?');
  80. temp_word = temp_word.substr(0, end);
  81. if (!queries.compare(0, end, temp_word)) {
  82. flag = 1;
  83. }
  84. }
  85. if (flag) {
  86. find_num++;
  87. }
  88. }
  89. }
  90. return find_num;
  91. }
  92.  
  93. int main() {
  94. std::vector <std::string> word{"frodo", "front","frost","frozen","frame","kakao"};
  95. std::vector <std::string> queries{ "fro??","????o","fr???","fro???","pro?" };
  96. for (int i = 0; i < queries.size(); i++) {
  97. printf("%d\n", find_word(queries[i], word));
  98. }
  99. return 0;
  100. }
  101. */
  102.  
  103.  
  104. /*효율성 테스트3 실패(2.65ms, 12.9MB)
  105. int find_word(std::string &queries, std::vector<std::string> &word) {
  106. std::string temp_word;
  107. int find_num = 0;
  108. bool flag = 1;
  109. for (int i = 0; i < word.size(); i++) {
  110. int fir, end;
  111. if (word[i].size() == queries.length()) {
  112. temp_word = word[i];
  113. flag = 0;
  114. if (queries[0] == '?') {
  115. fir = queries.find_first_not_of('?');
  116. end = queries.length() - fir;
  117. temp_word = temp_word.substr(fir, end);
  118. if (queries.compare(fir, end, temp_word) == 0) {
  119. flag = 1;
  120. }
  121. }
  122. else {
  123. end = queries.find_first_of('?');
  124. temp_word = temp_word.substr(0, end);
  125. if (!queries.compare(0, end, temp_word)) {
  126. flag = 1;
  127. }
  128. }
  129. if (flag) {
  130. find_num++;
  131. }
  132. }
  133. }
  134. return find_num;
  135. }
  136.  
  137. int main() {
  138. std::vector <std::string> word{ "frodo", "front","frost","frozen","frame","kakao" };
  139. std::vector <std::string> queries{ "fro??","????o","fr???","fro???","pro?" };
  140. for (int i = 0; i < queries.size(); i++) {
  141. printf("%d\n", find_word(queries[i], word));
  142. }
  143. return 0;
  144. }
  145. */
  146. /*효율성 테스트3 실패 시간초과
  147. int find_word(std::string &queries, std::vector<std::string> &word) {
  148. std::string temp_word;
  149. int find_num = 0;
  150. bool flag = 1;
  151. for (int i = 0; i < word.size(); i++) {
  152. int fir, end;
  153. if (word[i].size() == queries.length()) {
  154. temp_word = word[i];
  155. flag = 0;
  156. if (queries[0] == '?') {
  157. fir = queries.find_first_not_of('?');
  158. end = queries.length() - fir;
  159. if (fir == -1) {
  160. for (int k = 0; k < word.size(); k++) {
  161. if (word[k].size() == queries.length()) {
  162. find_num++;
  163. }
  164. }
  165. break;
  166. }
  167. temp_word = temp_word.substr(fir, end);
  168. if (queries.compare(fir, end, temp_word) == 0) {
  169. flag = 1;
  170. }
  171. }
  172. else {
  173. end = queries.find_first_of('?');
  174. temp_word = temp_word.substr(0, end);
  175. if (!queries.compare(0, end, temp_word)) {
  176. flag = 1;
  177. }
  178. }
  179. if (flag) {
  180. find_num++;
  181. }
  182. }
  183. }
  184. return find_num;
  185. }
  186. int main() {
  187. std::vector <std::string> word{ "frodo", "front","frost","frozen","frame","kakao" };
  188. std::vector <std::string> queries{ "?????","????o","fr???","fro???","pro?" };
  189. for (int i = 0; i < queries.size(); i++) {
  190. printf("%d\n", find_word(queries[i], word));
  191. }
  192. return 0;
  193. }
  194. */
  195.  
  196. /* 효율성 테스트3 실패(55.29ms, 13.4MB)
  197. int find_word(std::string &queries, std::vector<std::string> &word) {
  198. std::string temp_word;
  199. int find_num = 0;
  200. bool flag = 1;
  201. int size, length = queries.length();
  202. for (int i = 0; i < word.size(); i++) {
  203. int fir, end;
  204. size = word[i].size();
  205. if (size == length) {
  206. temp_word = word[i];
  207. flag = 0;
  208. if (queries[0] == '?') {
  209. fir = queries.find_first_not_of('?');
  210. end = length - fir;
  211. if (fir == -1) {
  212. for (int k = 0; k < size; k++) {
  213. if (word[k].size == length) {
  214. find_num++;
  215. }
  216. }
  217. break;
  218. }
  219. temp_word = temp_word.substr(fir, end);
  220. if (queries.compare(fir, end, temp_word) == 0) {
  221. flag = 1;
  222. }
  223. }
  224. else {
  225. end = queries.find_first_of('?');
  226. temp_word = temp_word.substr(0, end);
  227. if (!queries.compare(0, end, temp_word)) {
  228. flag = 1;
  229. }
  230. }
  231. if (flag) {
  232. find_num++;
  233. }
  234. }
  235. }
  236. return find_num;
  237. }
  238. int main() {
  239. std::vector <std::string> word{ "frodo", "front","frost","frozen","frame","kakao" };
  240. std::vector <std::string> queries{ "?????","????o","fr???","fro???","pro?" };
  241. for (int i = 0; i < queries.size(); i++) {
  242. printf("%d\n", find_word(queries[i], word));
  243. }
  244. return 0;
  245. }
  246. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement