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 ...
随机推荐
- VMware虚拟机克隆Linux(CentOS)系统后找不到eth0网卡的问题(图文详解)
问题现象: 有时候,会使用VMware虚拟机的的克隆功能,快速的复制已安装好的Linux系统. 可是克隆完之后,会发现没有eth0网卡. 解决办法: 1.编辑/etc/udev/rules.d/70 ...
- 前端组件化Polymer入门教程(5)——生命周期
以前我对生命周期这个概念还真不是很清楚,不过想想也简单,比如说人的生命周期,无非就是生老病死.而对于程序的生命周期就是说,它在每个阶段都会做不同的事,再比如说回调函数把,ajax返回的时候它才执行,那 ...
- MVC源码分析 - View
感觉好久没有学习了, 汗. 年就这么过完了, 感觉没有尝到过年的味道. 现在的年过的有些冷清了. 除了体重证明着我过了一个年, 还有一件值得开心的事情, 终于把女朋友变成未婚妻了. 这是一大进步吧. ...
- [Python] 震惊, 我居然用Python干这种事ꈍ .̮ ꈍ
阅读本文只需花费你两分钟, 两分钟你买不了吃亏,你也买不了上当. 那么, 为何不静下心来看看呢? Python 海龟创意绘画, Turtle库创作精美图画 Author:Amd794 E-ma ...
- 逆向工程-对native层的一次简单逆向实践
关注一款app很久了,这款app为了防止别人逆向破解拉取数据做了很多工作: 防止别人修改apk包,执行关键动作时对dex文件进行md5验证: 防止用户调用接口批量拉数据,对返回的web网页里个人信息进 ...
- 第一次项目上Linux服务器(三:安装Tomcat及相关命令)
一.下载Tomcat 去官网:http://tomcat.apache.org/ 找到要下载的Tomcat 本人下载的是apache-tomcat-8.5.29.tar.gz,百度云资源链接:链接:h ...
- web api中访问数据库的内存释放问题
在使用web api开发微信后台的时候,本来想像MVC一样在controller中申明dbcontext全局变量,其它地方直接使用就可以了,结果调试过程中发现使用dbcontext访问数据库并获取qu ...
- 【LeetCode题解】24_两两交换链表中的节点(Swap-Nodes-in-Pairs)
目录 描述 解法一:迭代 思路 Java 实现 Python 实现 复杂度分析 解法二:递归(不满足空间复杂度要求) 思路 Java 实现 Python 实现 复杂度分析 更多 LeetCode 题解 ...
- Huffman树与编码
带权路径最小的二叉树称为最优二叉树或Huffman(哈夫曼树). Huffman树的构造 将节点的权值存入数组中,由数组开始构造Huffman树.初始化指针数组,指针指向含有权值的孤立节点. b = ...
- arm裸板驱动总结(makefile+lds链接脚本+裸板调试)
在裸板2440中,当我们使用nand启动时,2440会自动将前4k字节复制到内部sram中,如下图所示: 然而此时的SDRAM.nandflash的控制时序等都还没初始化,所以我们就只能使用前0~40 ...