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

824. Goat Latin

时间:2018-06-16 15:38:10      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:Once   字符   dea   ret   处理   i++   red   ack   solution   

 1 class Solution 
 2 {
 3 public:
 4     string toGoatLatin(string S) 
 5     {
 6         S.push_back( );         //add a space that the loop can deal with the last word
 7         string a(150,a);        // string to add ‘a‘
 8         unordered_set<char> vowel={a,e,i,o,u,A,E,I,O,U};
 9         int front=0;
10         int len=S.size();
11         int alen=1;
12         string res;
13         for(int i=0;i<len;i++)      //once we meet a space ,we can deal with the word before it
14         {
15             if(S[i]== )
16             {
17                 string cur=S.substr(front,i-front);
18                 if(vowel.find(cur[0])==vowel.end())      
19                 {
20                     cur.push_back(cur[0]);
21                     cur.erase(cur.begin());
22                 }        
23                 res=res+cur+"ma"+a.substr(0,alen)+" ";
24                 alen++;
25                 front=i+1;
26             }
27         }
28         res.pop_back();    //delete the extra space
29         return res;
30     }
31 };

把原字符串剪断,一个单词一个单词处理,再把单词拼接成结果即可

824. Goat Latin

标签:Once   字符   dea   ret   处理   i++   red   ack   solution   

原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9190601.html

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