leetcode824
class Solution {
public:
void SplitString(const string& s, vector<string>& v, const string& c)
{
string::size_type pos1, pos2;
pos2 = s.find(c);
pos1 = ;
while (string::npos != pos2)
{
v.push_back(s.substr(pos1, pos2 - pos1));
pos1 = pos2 + c.size();
pos2 = s.find(c, pos1);
}
if (pos1 != s.length())
v.push_back(s.substr(pos1));
}
string toGoatLatin(string S) {
vector<string> V;
SplitString(S, V, " ");
set<char> ST;
ST.insert('a'); ST.insert('e'); ST.insert('i'); ST.insert('o'); ST.insert('u');
ST.insert('A'); ST.insert('E'); ST.insert('I'); ST.insert('O'); ST.insert('U');
string Result = "";
for (int i = ; i < V.size(); i++)
{
string word = V[i];
char begin = word[];
string newword = "";
if (ST.find(begin) != ST.end())//元音
{
newword = word + "ma";
}
else//辅音
{
string a = word.substr();
string b = word.substr(, );
newword = a + b + "ma";
}
for (int j = ; j <= i; j++)
{
newword += "a";
}
Result += newword;
if (i != V.size() - )
{
Result += " ";
}
}
return Result;
}
};
leetcode824的更多相关文章
- [Swift]LeetCode824. 山羊拉丁文 | Goat Latin
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...
- Leetcode824.Goat Latin山羊拉丁文
给定一个由空格分割单词的句子 S.每个单词只包含大写或小写字母. 我们要将句子转换为 "Goat Latin"(一种类似于 猪拉丁文 - Pig Latin 的虚构语言). 山羊拉 ...
随机推荐
- Struts02---实现struts2的三种方式
01.创建普通类 /** * 01.普通类 * 写一个execute() 返回String类型值 * */ public class HelloAction01 { public String exe ...
- fastclick插件 导致 日期插件无法触发
fastclick源文件中有这一行,加个if条件就可以了 当touchend的时候我们判断一下他的event.target到底是啥,如果是date我们就不玩了,不要你fastclick了,用原生的去触 ...
- 理解java异常处理机制
1. 引子 try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解.不过,我亲自体验的“教训”告诉我,这个东西可不是想象中的那么简单.听话. ...
- Android 中Activity,Window和View之间的关系
转自:http://hi.baidu.com/xiaofanqing/blog/item/8261ac114ab14f64cb80c435.html 我这里根据我个人的理解来讲讲我个人对这3个概念的理 ...
- Agilent RF fundamentals (3)- TX and RX
1Create carrier:谐振器,如433.92Mhz LC谐振 (频偏控制) 2Add data to carrier 加载数据 3Amplify to broadcast :放大器,如NPN ...
- JavaScript遍历树结构
遍历 function parseTreeJson(treeNodes){ if(!treeNodes||!treeNodes.length)return; for(let i=0;i<tree ...
- 记录下jplayer的简单demo
jplay一个播放器的工具包,依赖于jquery或者zepto,有zepto所以相当于是PC和移动都支持. 它的官方文档为:http://www.jplayer.cn/ 同时也推出的react的支持包 ...
- H264的编解码流程?
- canvas 绘制坐标轴
结果: 代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset="U ...
- 数据库查询操作(fetchone,fetchall)
数据库查询操作 Python查询Mysql使用 fetchone() 方法获取单条数据, 使用fetchall() 方法获取多条数据. fetchone(): 该方法获取下一个查询结果集.结果集是一个 ...