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的更多相关文章

  1. LeetCode算法题-Goat Latin Easy(Java实现)

    这是悦乐书的第322次更新,第344篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第192题(顺位题号是824).给出句子S,由空格分隔的单词组成.每个单词仅由小写和大写 ...

  2. 【LeetCode】824. Goat Latin 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. [LeetCode] Goat Latin 山羊拉丁文

    A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...

  4. LeetCode 824 Goat Latin 解题报告

    题目要求 A sentence S is given, composed of words separated by spaces. Each word consists of lowercase a ...

  5. [LeetCode&Python] Problem 824. Goat Latin

    A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...

  6. [LeetCode] 824. Goat Latin

    Description A sentence S is given, composed of words separated by spaces. Each word consists of lowe ...

  7. C#LeetCode刷题之#824-山羊拉丁文​​​​​​​(Goat Latin)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3971 访问. 给定一个由空格分割单词的句子 S.每个单词只包含大 ...

  8. 824. Goat Latin - LeetCode

    Questioin 824. Goat Latin Solution 题目大意:根据要求翻译句子 思路:转换成单词数组,遍历数组,根据要求转换单词 Java实现: 用Java8的流实现,效率太低 pu ...

  9. [Swift]LeetCode824. 山羊拉丁文 | Goat Latin

    A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...

随机推荐

  1. Window服务与Quartz.NET

    Quartz.NET: http://quartznet.sourceforge.net/ (现为2.2版本) Sourceforge:http://sourceforge.net/projects/ ...

  2. C++学习知识点

    所谓的学习,知识只是一部分,理解知识是如何被抽象和提炼的过程,才是更重要的 1.c++代码里面的\(反斜杠) C语言的宏要求只能在同一行,是不能跨行的.这里的反斜杠就是告诉编译器,我这里虽然换行了,但 ...

  3. logstash-input-jdbc同时同步多个表

    同步一个表,可以参考我的上一篇 logstash-jdbc-input与mysql数据库同步 同步多个表的做法,跟一个表类似,唯一不同的是 .conf 文件中的配置 在这里我加了一个脚本文件jdbc- ...

  4. SpringMVC之表单校验

    SpringMVC已经实现了对Java校验API(JSR-303)的支持,通过使用该API可以实现对数据的校验.要使用SpringMVC的Java校验API并不需要任何配置,只要引入其实现即可.本文使 ...

  5. WPF 数据绑定 使用Code First with Database

    一.准备工作 1.开发工具 Visual Studio 2013 2.安装 Entity Framework 6 Tools for Visual Studio 2012 & 2013 来实现 ...

  6. 【详解】JNI(Java Native Interface)(一)

    前言: 一提到JNI,多数编程者会下意识地感受到一种无法言喻的恐惧.它给人的第一感觉就是"难",因为它不是单纯地在JVM环境内操作Java代码,而是跳出虚拟机与其他编程语言进行交互 ...

  7. python中os模块的walk函数

    Python的文档中对walk的介绍: walk(top, topdown=True, onerror=None, followlinks=False) 树状目录的生成器. 对于以top参数为根的目录 ...

  8. jdbc mysql driver 6.0.2

    url = jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=UTF-8&useLegac ...

  9. MQ5.3在redhat9上的安装

    一.准备工作 1.安装linux软件包 确保系统中有libgcc_s.so和libstdc++.so.3. 如无意外,libgcc_s.so在redhat中已经存在,存放路径为:/usr/lib/gc ...

  10. window对象方法之setTimeout(),setInterval()

    window中的这两个方法是比较重要的,在许多的设计中会使用到这两个方法.比如使用在倒计时抢购中. 首先来说说这两个方法的用法吧! 一:window.setTimeout(); setTimeout( ...