码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode-966 Vowel Spellchecker(元音拼写检查器)

时间:2018-12-30 17:21:54      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:cto   def   LLC   lis   ring   check   vector   count   bsp   

 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(元音拼写检查器)

标签:cto   def   LLC   lis   ring   check   vector   count   bsp   

原文地址:https://www.cnblogs.com/Asurudo/p/10199702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!