LeetCode 题解之Goat Latin
1、问题描述

2、问题分析
将句子拆分成单词,然后放入vector中,对每一个单词做改变,最后连成句子返回。
3、代码
string toGoatLatin(string S) {
vector<string> words;
for(string::iterator it = S.begin() ; it != S.end(); ++it ){
string::iterator it_i = it ;
while( it_i != S.end() && isalpha( *it_i) ){
++it_i ;
}
string word(it,it_i);
words.push_back( word );
if( it_i != S.end() ){
it = it_i;
}else{
it = it_i - ;
}
}
string result ;
string a = "a";
set<string> vowels{"a","e","i","o","u","A","E","I","O","U"};
for( auto &s : words ){
if( vowels.find( s.substr(,) ) != vowels.end() ){
s += "ma";
}else{
s += s[];
s.erase( s.begin() );
s += "ma";
}
s += a;
a += "a";
result += s += " ";
}
result.erase( result.end() - );
return result ;
}
LeetCode 题解之Goat Latin的更多相关文章
- LeetCode算法题-Goat Latin Easy(Java实现)
这是悦乐书的第322次更新,第344篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第192题(顺位题号是824).给出句子S,由空格分隔的单词组成.每个单词仅由小写和大写 ...
- 【LeetCode】824. Goat Latin 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [LeetCode] Goat Latin 山羊拉丁文
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...
- LeetCode 824 Goat Latin 解题报告
题目要求 A sentence S is given, composed of words separated by spaces. Each word consists of lowercase a ...
- [LeetCode&Python] Problem 824. Goat Latin
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...
- [LeetCode] 824. Goat Latin
Description A sentence S is given, composed of words separated by spaces. Each word consists of lowe ...
- C#LeetCode刷题之#824-山羊拉丁文(Goat Latin)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3971 访问. 给定一个由空格分割单词的句子 S.每个单词只包含大 ...
- 824. Goat Latin - LeetCode
Questioin 824. Goat Latin Solution 题目大意:根据要求翻译句子 思路:转换成单词数组,遍历数组,根据要求转换单词 Java实现: 用Java8的流实现,效率太低 pu ...
- [Swift]LeetCode824. 山羊拉丁文 | Goat Latin
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...
随机推荐
- js获取上一个兄弟元素
需要用到的两个属性:previousSbiling和previousElementSibling previousSibling:获取元素的上一个兄弟节点:(既包含元素节点.文本节点.注释节点) pr ...
- tomcat如何正确的开启远程调试功能
在日常开发中,有时需要对远程服务器上的应用进行远程调试,对于tomcat,要进行远程调试其实很简单,只需要在启动tomcat时开启jpda服务即可. 什么是JPDA呢? JPDA(JavaPlatfo ...
- tensorflow 在同一个GPU同时加载多张相同的图
saver = self.tf_instance.train.Saver() self.sess = self.tf_instance.Session(config=sess_config, grap ...
- 了解Spring-boot-starter常用依赖模块
Spring-boot的优点: 1.Spring框架的“约定优先于配置(COC)”理念以及最佳实践. 2.针对日常企业应用研发各种场景的Spring-boot-starter自动配置依赖模块,且“开箱 ...
- WPF性能优化的一些建议
尽量多使用Canvas等简单的布局元素,少使用Grid或者StackPanel等复杂的,减小开销. 少用Margin Padding尤其避免嵌套使用. 在自定义控件,尽量不要在控件的ResourceD ...
- PowerBuilder编程新思维4:钩挂(界面美化与DirectUI)
<第二部分 Outside> PowerBuilder编程新思维4:钩挂(界面美化与DirectUI) PB的界面由于其封闭性,一直以来都是最大的弱项.自PB9.0开放了PBNI接口后,开 ...
- Netty 核心组件 Pipeline 源码分析(二)一个请求的 pipeline 之旅
目录大纲: 前言 针对 Netty 例子源码做了哪些修改? 看 pipeline 是如何将数据送到自定义 handler 的 看 pipeline 是如何将数据从自定义 handler 送出的 总结 ...
- .36-浅析webpack源码之Parser类
眼看webpack4都出了,我还在撸3的源码,真的是捉急啊…… 不过现在只是beta版本,等出稳定版本后跑跑4的源码去. 之前漏了一个东西没有讲,如下: asyncLib.parallel([/**/ ...
- MVC会员注销功能Cookie的应用
我们实现了<MVC应用程序实现会员登录功能>http://www.cnblogs.com/insus/p/3466512.html 有登录就会有注销功能.此次Insus.NET练习一个MV ...
- Redis列表操作
列表类似于双向链表结构,可从序列两端推入或者弹出元素. (列表常用命令) RPUSH : RPUSH key-name value [value1 value2,...] ------------将 ...