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 ...
随机推荐
- JVM(四)JVM的双亲委派模型
1.两种不同的类加载器 从JAVA虚拟机的角度来讲,只存在两种不同的类加载器:一种是启动类加载器(Bootstrap ClassLoader),这个类加载器使用C++语言实现,是虚拟机自身的一部分:另 ...
- C#基础篇六飞行棋
飞行棋业务:我们要能够让2个玩家 在地图上 按照游戏规则 进行游戏 玩家类 变量:玩家位置,玩家名称,玩家标识,玩家是否在陷阱中 方法:投骰子,移动 地图类 变量:地图数据数组 方法:初始化地图数据, ...
- Sublime Text3 一些实用设置
字体大小 "font_size": 14 高亮编辑中的那一行 "highlight_line": true 当你把脑袋扭过到显示器以外的地方后再回头看编辑器,光 ...
- 关于oracle的缓冲区机制与HDFS中的edit logs的某些关联性的思考
可能大家会问,oracle和HDFS属于不同场景的存储系统,它们之间为什么会有联系呢?确实,从技术本身来看,他们确实无关联,但利用“整体学习”的思想,跳出技术本身,可以发现Oracle的缓冲区和HDF ...
- mongo学习使用记录2 spring data
spring data mongo 打印mongo NoSql语句 log4j.properties log4j.rootLogger=INFO, stdout log4j.logger.org.sp ...
- mongodb索引--1亿条记录的查询从55.7秒到毫秒级别<补充版>
从头开始,验证mongodb的索引的好处.(window7环境下) 下载mongodb服务器,并解压到d盘,并使用以下命令启动 mongod --dbpath D:\mongodb\data mong ...
- 纯css竟可以做出边框这样长宽度的过渡效果
边框效果如下:鼠标移到下面方形,就有效果 要是没有效果,点这个:https://murenziwei.github.io/testGit/Untitled1.html 正如你所看到的,这边框颜色只 ...
- VS2012 扩展和更新里 插件状态 为禁用 的解决办法!
在vs2012 里安装完插件,重启VS,结果 插件没有加载,查看 扩展和更新,里面显示禁用,如图: 解决方法: 点击界面上 “启用每用户扩展的加载” 蓝色文字,弹出如下界面: 选中 以管理员运行时加载 ...
- ASP.NET MVC显示UserControl控件(扩展篇)
昨晚Insus.NET有怀旧一下<念念不忘,ASP.NET MVC显示WebForm网页或UserControl控件>http://www.cnblogs.com/insus/p/3641 ...
- Spring基础(8) : properties配置文件
<context:property-placeholder location="p.properties"/> <bean id="p" cl ...