class Solution
{
public:
string toGoatLatin(string S)
{
S.push_back(' '); //add a space that the loop can deal with the last word
string a(,'a'); // string to add 'a'
unordered_set<char> vowel={'a','e','i','o','u','A','E','I','O','U'};
int front=;
int len=S.size();
int alen=;
string res;
for(int i=;i<len;i++) //once we meet a space ,we can deal with the word before it
{
if(S[i]==' ')
{
string cur=S.substr(front,i-front);
if(vowel.find(cur[])==vowel.end())
{
cur.push_back(cur[]);
cur.erase(cur.begin());
}
res=res+cur+"ma"+a.substr(,alen)+" ";
alen++;
front=i+;
}
}
res.pop_back(); //delete the extra space
return res;
}
};

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

824. Goat Latin的更多相关文章

  1. 【Leetcode_easy】824. Goat Latin

    problem 824. Goat Latin solution class Solution { public: string toGoatLatin(string S) { unordered_s ...

  2. 824. Goat Latin - LeetCode

    Questioin 824. Goat Latin Solution 题目大意:根据要求翻译句子 思路:转换成单词数组,遍历数组,根据要求转换单词 Java实现: 用Java8的流实现,效率太低 pu ...

  3. LeetCode 824 Goat Latin 解题报告

    题目要求 A sentence S is given, composed of words separated by spaces. Each word consists of lowercase a ...

  4. [LeetCode&Python] Problem 824. Goat Latin

    A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...

  5. 824. Goat Latin山羊拉丁文

    [抄题]: A sentence S is given, composed of words separated by spaces. Each word consists of lowercase ...

  6. [LeetCode] 824. Goat Latin

    Description A sentence S is given, composed of words separated by spaces. Each word consists of lowe ...

  7. 【LeetCode】824. Goat Latin 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  8. LeetCode 824. Goat Latin (山羊拉丁文)

    题目标签:String 首先把vowel letters 保存入 HashSet. 然后把S 拆分成 各个 word,遍历每一个 word: 当 word 第一个 字母不是 vowel 的时候,把第一 ...

  9. LeetCode算法题-Goat Latin Easy(Java实现)

    这是悦乐书的第322次更新,第344篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第192题(顺位题号是824).给出句子S,由空格分隔的单词组成.每个单词仅由小写和大写 ...

随机推荐

  1. WAS 手动删除server

    有时候WPS Server上的应用会一直start不起来,尝试卸载也会失败.在这种情况下,我们可以手动删除这个文件. 步骤如下: 1. Stop server 2. 进入$Profile_instal ...

  2. decay

    decay - 必应词典 美[dɪ'keɪ]英[dɪ'keɪ] v.衰减:腐朽:衰败 n.腐烂:衰退:腐朽 网络衰变:腐败 变形过去分词:decayed:现在分词:decaying:第三人称单数:de ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心或有源汇上下界网络流)

    "Oh, There is a bipartite graph.""Make it Fantastic."X wants to check whether a ...

  4. TZOJ 4621 Grammar(STL模拟)

    描述 Our strings only contain letters(maybe the string contains nothing). Now we define the production ...

  5. [Java学习]集合

    一. Collection与Map继承结构图 Collection继承结构图 实现Collection接口的类只能存储引用类型!所以set.add(10)会有自动装箱的过程,把int 转成 Integ ...

  6. pa sslvpn使用手册

    1.浏览器输入https://x.x.x.x 根据电脑操作系统及位数选择下载 2.安装 直接“下一步”,到  输入IP地址x.x.x.x 点击连接会有证书错误提示 此时点击显示证书→本地计算机→安装到 ...

  7. c#: TabControl隐藏选项卡(WizardPages)

    如Delphi之TPageControl控件,其TTabSheet有TabVisible属性,在制作类似Wizard页面切换时,甚为有用. 而c#对应之TabControl控件,其页面TabPage无 ...

  8. Kylin 与 Spark SQL相比,有哪些差异和优势

    SparkSQL本质上是基于DAG模型的MPP.而Kylin核心是Cube(多维立方体).关于MPP和Cube预处理的差异,重复如下: > MPP [1] 的基本思路是增加机器来并行计算,从而提 ...

  9. require模块化载入

    1,模块化require的载入步骤 1,一个总文件夹,,里面三个子文件夹 ,, 分别是 2,common 里面是放一些公共方法和自己封装的方法     js里面是放自己的业务逻辑js文件和一些模块化的 ...

  10. swift - UIWebView 和 WKWebView(iOS12 之后替换UIWebView)

    1.iOS12 之前 使用 UIWebView 1> private lazy var webV : UIWebView = { let v = UIWebView(frame: self.vi ...