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. [剑指Offer]35-复杂链表的复制

    链接 https://www.nowcoder.com/practice/f836b2c43afc4b35ad6adc41ec941dba?tpId=13&tqId=11178&tPa ...

  2. elasticsearch查询语句总结

    query 和  filter 的区别请看:https://www.cnblogs.com/bainianminguo/articles/10396956.html Filter DSL term 过 ...

  3. jquery实现元素高度变化页面变化

    试了几种方法包括有资料说的h5新特性,都没能满足我的需求.我的需求如下: 元素高度是动态可变的,比如可拖动teatarea元素 最后用到了指针监听事件解决了 @参考文档 $(document).mou ...

  4. mysql 5.6 datetime 保存精确到秒

    mysql中的CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP 设置默认值 now(3)  datetime 长度  3   保存精确到秒

  5. swift - 全屏imageView的适配 - UIViewContentMode选择

    1. /// 设置当前图片view大小 func setFrame(){ if #available(iOS 11.0, *) { if let y = JY_WINDOW?.safeAreaInse ...

  6. 支付宝H5 与网页端支付开发

    在日常生活中,我们基本上都是进行微信与支付宝的支付方式尽心支付,这种方式确实大大便利了我们的生活,那么如何在我们的产品中进行微信与支付宝支付的植入开发呢? 我们先进行支付宝的H5与网页端支付开发,这里 ...

  7. AngularJS——第1章 简介

    第1章 简介 由谷歌公司开发维护的前端MVC框架,克服了HTML在构建应用上的诸多不足,降低了开发成本,提高了效率. 一个框架 以数据和逻辑作为驱动 AngularJS核心特性:模块化,双数据绑定,语 ...

  8. Bootstrap(5)栅格系统

    一.移动设备优先 在 HTML5 的项目中,我们做了移动端的项目.它有一份非常重要的 meta,用于设置屏幕和设备等宽以及是否运行用户缩放,及缩放比例的问题. //分别为:屏幕宽度和设备一致.初始缩放 ...

  9. docker-ce-17.09 数据卷和数据卷容器

    docker容器中管理数据两种方式:1.数据卷(Data Volumes)2.数据卷容器(Data Volume Dontainers) 一.数据卷特性:1.数据卷可以在容器之间共享和重用2.对数据卷 ...

  10. python bisect 排序模块 二分查找与 bisect 模块

    python 3.6.5 import bisect bisect_list=dir(bisect)print(bisect_list)bisect_list = ['__builtins__', ' ...