Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<vector>
- /* 효율성 테스트3 실패(5.98ms, 15.1MB)
- int find_word(std::string queries, std::vector<std::string> &word) {
- std::string temp_word;
- int find_num = 0;
- bool flag = 1;
- for (int i = 0; i < word.size(); i++) {
- int fir, end;
- if (word[i].size() == queries.length()) {
- temp_word = word[i];
- flag = 0;
- if (queries[0] == '?') {
- fir = queries.find_first_not_of('?');
- end = queries.length() - fir;
- temp_word = temp_word.substr(fir, end);
- if (queries.compare(fir, end, temp_word) == 0) {
- flag = 1;
- }
- }
- else {
- end = queries.find_first_of('?');
- temp_word = temp_word.substr(0, end);
- if (!queries.compare(0, end, temp_word)) {
- flag = 1;
- }
- }
- if (flag) {
- find_num++;
- }
- }
- }
- return find_num;
- }
- int main() {
- std::vector <std::string> word{ "frodo", "front","frost","frozen","frame","kakao" };
- std::vector <std::string> queries{ "fro??","????o","fr???","fro???","pro?" };
- for (int i = 0; i < queries.size(); i++) {
- std::vector<std::string> word2 = word;
- for (int k = 0; k < word2.size(); k++) {
- if (word2[k].length() != queries[i].length()) {
- word2.erase(word2.begin()+k);
- k--;
- }
- }
- printf("%d\n", find_word(queries[i], word2));
- }
- return 0;
- }
- */
- /* 효율성 테스트3 실패 (5.78ms, 12.9MB)
- int find_word(std::string queries, std::vector<std::string> &word) {
- std::string temp_word;
- int find_num = 0;
- bool flag = 1;
- for (int i = 0; i < word.size(); i++) {
- int fir,end;
- if (word[i].size() == queries.length()) {
- temp_word = word[i];
- flag = 0;
- if (queries[0] == '?') {
- fir = queries.find_first_not_of('?');
- end = queries.length() - fir;
- temp_word = temp_word.substr(fir, end);
- if (queries.compare(fir, end, temp_word)==0) {
- flag = 1;
- }
- }
- else {
- end=queries.find_first_of('?');
- temp_word = temp_word.substr(0, end);
- if (!queries.compare(0, end, temp_word)) {
- flag = 1;
- }
- }
- if (flag) {
- find_num++;
- }
- }
- }
- return find_num;
- }
- int main() {
- std::vector <std::string> word{"frodo", "front","frost","frozen","frame","kakao"};
- std::vector <std::string> queries{ "fro??","????o","fr???","fro???","pro?" };
- for (int i = 0; i < queries.size(); i++) {
- printf("%d\n", find_word(queries[i], word));
- }
- return 0;
- }
- */
- /*효율성 테스트3 실패(2.65ms, 12.9MB)
- int find_word(std::string &queries, std::vector<std::string> &word) {
- std::string temp_word;
- int find_num = 0;
- bool flag = 1;
- for (int i = 0; i < word.size(); i++) {
- int fir, end;
- if (word[i].size() == queries.length()) {
- temp_word = word[i];
- flag = 0;
- if (queries[0] == '?') {
- fir = queries.find_first_not_of('?');
- end = queries.length() - fir;
- temp_word = temp_word.substr(fir, end);
- if (queries.compare(fir, end, temp_word) == 0) {
- flag = 1;
- }
- }
- else {
- end = queries.find_first_of('?');
- temp_word = temp_word.substr(0, end);
- if (!queries.compare(0, end, temp_word)) {
- flag = 1;
- }
- }
- if (flag) {
- find_num++;
- }
- }
- }
- return find_num;
- }
- int main() {
- std::vector <std::string> word{ "frodo", "front","frost","frozen","frame","kakao" };
- std::vector <std::string> queries{ "fro??","????o","fr???","fro???","pro?" };
- for (int i = 0; i < queries.size(); i++) {
- printf("%d\n", find_word(queries[i], word));
- }
- return 0;
- }
- */
- /*효율성 테스트3 실패 시간초과
- int find_word(std::string &queries, std::vector<std::string> &word) {
- std::string temp_word;
- int find_num = 0;
- bool flag = 1;
- for (int i = 0; i < word.size(); i++) {
- int fir, end;
- if (word[i].size() == queries.length()) {
- temp_word = word[i];
- flag = 0;
- if (queries[0] == '?') {
- fir = queries.find_first_not_of('?');
- end = queries.length() - fir;
- if (fir == -1) {
- for (int k = 0; k < word.size(); k++) {
- if (word[k].size() == queries.length()) {
- find_num++;
- }
- }
- break;
- }
- temp_word = temp_word.substr(fir, end);
- if (queries.compare(fir, end, temp_word) == 0) {
- flag = 1;
- }
- }
- else {
- end = queries.find_first_of('?');
- temp_word = temp_word.substr(0, end);
- if (!queries.compare(0, end, temp_word)) {
- flag = 1;
- }
- }
- if (flag) {
- find_num++;
- }
- }
- }
- return find_num;
- }
- int main() {
- std::vector <std::string> word{ "frodo", "front","frost","frozen","frame","kakao" };
- std::vector <std::string> queries{ "?????","????o","fr???","fro???","pro?" };
- for (int i = 0; i < queries.size(); i++) {
- printf("%d\n", find_word(queries[i], word));
- }
- return 0;
- }
- */
- /* 효율성 테스트3 실패(55.29ms, 13.4MB)
- int find_word(std::string &queries, std::vector<std::string> &word) {
- std::string temp_word;
- int find_num = 0;
- bool flag = 1;
- int size, length = queries.length();
- for (int i = 0; i < word.size(); i++) {
- int fir, end;
- size = word[i].size();
- if (size == length) {
- temp_word = word[i];
- flag = 0;
- if (queries[0] == '?') {
- fir = queries.find_first_not_of('?');
- end = length - fir;
- if (fir == -1) {
- for (int k = 0; k < size; k++) {
- if (word[k].size == length) {
- find_num++;
- }
- }
- break;
- }
- temp_word = temp_word.substr(fir, end);
- if (queries.compare(fir, end, temp_word) == 0) {
- flag = 1;
- }
- }
- else {
- end = queries.find_first_of('?');
- temp_word = temp_word.substr(0, end);
- if (!queries.compare(0, end, temp_word)) {
- flag = 1;
- }
- }
- if (flag) {
- find_num++;
- }
- }
- }
- return find_num;
- }
- int main() {
- std::vector <std::string> word{ "frodo", "front","frost","frozen","frame","kakao" };
- std::vector <std::string> queries{ "?????","????o","fr???","fro???","pro?" };
- for (int i = 0; i < queries.size(); i++) {
- printf("%d\n", find_word(queries[i], word));
- }
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement