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 忘记密码

    一.重置密码 1.首先关闭was,ps –ef|grep java 查看java进程号,然后kill -9 XXXX杀掉进程即可.或者使用命令./stopServer.sh server1 2.取消控 ...

  2. Lua入门教程

    什么是Lua Lua 是一个小巧的脚本语言.是巴西里约热内卢天主教大学(Pontifical Catholic University of Rio de Janeiro)里的一个研究小组,由Rober ...

  3. Disruptor并发框架简介

    Martin Fowler在自己网站上写一篇LMAX架构的文章,在文章中他介绍了LMAX是一种新型零售金额交易平台,它能够以很低的延迟产生大量交易.这个系统是建立在JVM平台上,其核心是一个业务逻辑处 ...

  4. makefile文件操作大全

     Makefile的规则 -- 转自 :http://blog.csdn.net/ruglcc/article/details/7814546/ 在讲述这个Makefile之前,还是让我们先来粗略地看 ...

  5. python第三方库requests简单介绍

    一.发送请求与传递参数 简单demo: import requests r = requests.get(url='http://www.itwhy.org') # 最基本的GET请求 print(r ...

  6. Exceptions

    [定义] error: external, like out of memory exception: internal, like file not found 父类都是throwable 逻辑有错 ...

  7. Incorrect Invoice Ref.

    IF_EX_ACC_DOCUMENT~CHANGE LOOP AT c_accit ASSIGNING <wa_accit> WHERE rebzg eq 'V'. <wa_acci ...

  8. 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX(转)

    原文地址:https://www.cnblogs.com/feng18/p/5646925.html 从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'g ...

  9. 工作中用Git对项目进行管理

    前言 之前一直是用svn来管理代码的,今天第一次用git来管理代码,从安装.上传代码过程中遇到了很多问题,Github中建的repository之前还是https协议,最后不知道怎么又变成了git协议 ...

  10. vue 自定义组件directives

    自定义指令:以v开头,如:v-mybind. 代码示例: <input v-mybind /> directives:{ mybind:{ bind:function (el) { el. ...