Leetcode-966 Vowel Spellchecker(元音拼写检查器)
Posted Asurudo Jyo の 倉 庫
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-966 Vowel Spellchecker(元音拼写检查器)相关的知识,希望对你有一定的参考价值。
1 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 2 class Solution 3 { 4 public: 5 vector<string> spellchecker(vector<string>& wordlist, vector<string>& queries) 6 { 7 vector<string> rnt; 8 set<string> ws; 9 map<string,int> wxs; 10 map<string,int> wys; 11 12 _for(i,0,wordlist.size()) 13 ws.insert(wordlist[i]); 14 _for(i,0,wordlist.size()) 15 { 16 string tmp = wordlist[i]; 17 _for(j,0,tmp.size()) 18 tmp[j] = tolower(tmp[j]); 19 if(!wxs.count(tmp)) 20 wxs.insert({tmp,i}); 21 } 22 _for(i,0,wordlist.size()) 23 { 24 string tmp = wordlist[i]; 25 _for(j,0,tmp.size()) 26 { 27 tmp[j] = tolower(tmp[j]); 28 if(tmp[j]==‘a‘||tmp[j]==‘e‘||tmp[j]==‘i‘ 29 ||tmp[j]==‘o‘||tmp[j]==‘u‘) 30 tmp[j] = ‘*‘; 31 } 32 if(!wys.count(tmp)) 33 wys.insert({tmp,i}); 34 } 35 36 _for(i,0,queries.size()) 37 { 38 if(ws.count(queries[i])) 39 {rnt.push_back(queries[i]);continue;} 40 41 string tmp = queries[i]; 42 _for(j,0,tmp.size()) 43 tmp[j] = tolower(tmp[j]); 44 auto pp = wxs.find(tmp); 45 if(pp!=wxs.end()) 46 { 47 rnt.push_back(wordlist[pp->second]); 48 continue; 49 } 50 51 _for(j,0,tmp.size()) 52 if(tmp[j]==‘a‘||tmp[j]==‘e‘||tmp[j]==‘i‘ 53 ||tmp[j]==‘o‘||tmp[j]==‘u‘) 54 tmp[j]=‘*‘; 55 auto pp2 = wys.find(tmp); 56 if(pp2!=wys.end()) 57 { 58 rnt.push_back(wordlist[pp2->second]); 59 continue; 60 } 61 rnt.push_back(""); 62 } 63 return rnt; 64 } 65 };
以上是关于Leetcode-966 Vowel Spellchecker(元音拼写检查器)的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp Longest_common_vowel_subsequence
HDU 3079 Vowel Counting (水题。。。判断元音)
[LeetCode] 2559. Count Vowel Strings in Ranges
杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》