Leetcode-5018 Camelcase Matching(驼峰式匹配)

 1 class Solution
 2 {
 3     public:
 4         vector<bool> camelMatch(vector<string>& queries, string pattern)
 5         {
 6             vector<bool> rnt(queries.size());
 7 
 8             for(int i = 0; i < queries.size(); i ++)
 9             {
10                 int qin = 0,pin = 0;
11                 bool rr = true;
12                 
13                 string ss1,ss2;
14                 for(int j = 0;j < queries[i].size();j ++)
15                     if(isupper(queries[i][j]))
16                         ss1 += queries[i][j];
17                 for(int j = 0;j < pattern.size();j ++)
18                     if(isupper(pattern[j]))
19                         ss2 += pattern[j];
20                 if(ss1!=ss2)
21                 {
22                     rnt[i] = false;
23                     continue;
24                 }
25                 while(qin < queries[i].size() && pin < pattern.size())
26                 {
27                     if(isupper(queries[i][qin]) && islower(pattern[pin]))
28                     {
29                         rr = false;
30                         break;
31                     }
32                     else if(isupper(queries[i][qin]) && isupper(pattern[pin]))
33                     {
34                         if(queries[i][qin]==pattern[pin])
35                         {
36                             qin ++;
37                             pin ++;
38                         }
39                         else
40                         {
41                             rr = false;
42                             break;
43                         }
44                     }
45                     else if(islower(queries[i][qin]) && isupper(pattern[pin]))
46                         qin ++;
47                     else
48                     {
49                         if(queries[i][qin]==pattern[pin])
50                         {
51                             qin ++;
52                             pin ++;
53                         }
54                         else
55                             qin ++;    
56                     }
57                 }
58                 
59                 int sz = pattern.size();
60                 if(pin<sz)
61                     rr = false;
62                 rnt[i] = rr;
63             }
64             return rnt;
65         }
66 };

想一套匹配规则去遍历匹配就可以了,写了几十分钟,不知道在写什么

posted @ 2019-04-07 13:31  Asurudo  阅读(309)  评论(0编辑  收藏  举报