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 的虚构语言). 山羊拉 ...
随机推荐
- 【Wannafly挑战赛9-B】数一数
链接:https://www.nowcoder.net/acm/contest/71/B 题目就不贴了.. 设res[i]为第i行的最终结果,可以想到,res[i]为0或不为0.长度不是最短的字符串r ...
- ArrayList、Vector、LinkedList(jdk8)
一.ArrayList分析 1.类和构造方法 public class ArrayList<E> extends AbstractList<E> //可以看到其父类是Abstr ...
- L137
Uncontacted Tribes at Risk Amid ‘Worrying' Surge in Amazon Deforestation Illegal loggers and militia ...
- 常用algorithm及其Python实现
冒泡排序 def bubble_sort(li): for i in range(len(li)-1): # i表示第几趟 for j in range(len(li)-i-1): # j表示图中的箭 ...
- [置顶]
Kubernetes1.7新特性:新增自动伸缩条件和参数
一.核心概念 Horizontal Pod Autoscaling,简称HPA,是Kubernetes中实现POD水平自动伸缩的功能.云计算具有水平弹性的特性,这个是云计算区别于传统IT技术架构的主要 ...
- Arcgis for Javascript之featureLayer图和属性的互操作
说明:主要实现加载FeatureLayer与显示属性表,并实现属性表与地图的联动,首先,看看实现后的效果: 显示效果 如上图所示,本文章主要实现了以下几个功能:1.FeatureLayer属性表的分页 ...
- js将json数据动态生成表格
今天开发中遇到需要展示动态数据的问题, 具体要求是后端传来的json字符串,要在前端页面以table表格的形式展示, 其实没啥难的,就是拼接table标签,纯属体力活,于是自己写了个呆萌,保存起来,以 ...
- php打印乘法口诀表
<?php $n=9; //动态控制乘法口诀表的行数 echo"<table>"; //外层循环控制行数 for($i=1;$i<=$n;$i++){ // ...
- 卷积神经网络实战-----0001(移植卷积神经网络c++ to python or java)
1. https://github.com/174high/simple_cnn 自己fork的 2. https://github.com/can1357/simple_cnn 最初始的 3. ...
- 剑指Offer面试题:8.二进制中1的个数
一 题目:二进制中1的个数 题目:请实现一个整数,输出该数二进制表示中1的个数.例如把9表示成二进制是1001,有2位是1.因此如果输入9,该函数输出2. 二 可能引起死循环的解法 // 计算整数的二 ...