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. NumPy 迭代数组

    NumPy 迭代数组 NumPy 迭代器对象 numpy.nditer 提供了一种灵活访问一个或者多个数组元素的方式. 迭代器最基本的任务的可以完成对数组元素的访问. 接下来我们使用 arange() ...

  2. 01背包 hdu1864

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1864 注意事项: 在这里所有输入的价格都是两位小数(题目没说,看论坛才知道的). 这里单项价格不能超过 ...

  3. Mobile Game Development with Unity Build Once, Deploy Anywhere

    本书从自上而下的角度介绍了Unity游戏引擎的功能,并提供了具体的.面向项目的指导,说明了如何在真实的游戏场景中使用这些功能,以及如何从头开始构建让玩家爱不释手的2D和3D游戏.主要内容有:探索Uni ...

  4. HTTP 基础

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...

  5. [Java学习]常用类-包装类型

    八种基本类型对应的包装类 Java中的数据类型由八种基本类型,以及引用类型组成. byte short int long float double boolbean char Object 为了方便, ...

  6. swift - 基础属性 - 属性写法

    var num1 : Int = 0 var num2 : Int = 5 /// 1.计算属性 var num3 : Int{ return num1 + num2 } /// 2.闭包属性 pri ...

  7. html与css关系

    1.html是网页的内容的载体 内容是作者发在页面想让用户浏览的信息,包括文字,图片,视频等 2.css样式是表现 像网页的外衣,比如标题字体的变化,颜色的变化,背景颜色,边框等,所有这些都是用来改变 ...

  8. 织梦替换ueditor百度编辑器,支持图片水印 教程

    1下载ueditor百度编辑器 2 把下载的zip解压得到ueditor文件夹,把解压到的ueditor文件夹扔进你网站的include文件夹去 3 打开 /include/inc/inc_fun_f ...

  9. andorid 单选与复选

    activity_ui1.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...

  10. MySQL 索引 INDEX

    索引用于快速找出在某列中有特定值的行. 不使用索引,MySQL必须从第一条记录开始读完整个表,直到找到相关的行,表越大,查询数据所花费的时间就越多,如果表中查询的列有一个索引,MySQL能够快速到达一 ...