当前位置:网站首页>LeetCode 山羊拉丁文[模拟 字符串] HERODING的LeetCode之路
LeetCode 山羊拉丁文[模拟 字符串] HERODING的LeetCode之路
2022-04-21 19:34:00 【HERODING23】

解题思路:
一道非常简单的模拟题,没有什么特别的解题思路,需要一个容器存储元音字母,一个变量存储每个单词首字母位置(判断元音以及非元音放后面操作),一个变量统计单词的索引,最后不要忘了每次遍历一个单词后把‘ ’放入字符串中,代码如下:
class Solution {
public:
string toGoatLatin(string sentence) {
unordered_set<char> alpha = {
'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
// 定义每个字母的首字母位置,当前字母索引
int index = 0, cnt = 1, n = sentence.size();
string s;
for(int i = 0; i <= n; i ++) {
if(i < n && sentence[i] != ' ') {
continue;
} else {
if(alpha.count(sentence[index])) {
s += sentence.substr(index, i - index) + "ma" + string(cnt, 'a');
} else {
s += sentence.substr(index + 1, i - index - 1) + sentence[index] + "ma" + string(cnt, 'a');
}
cnt ++;
index = i + 1;
if(i != n) s += ' ';
}
}
return s;
}
};
版权声明
本文为[HERODING23]所创,转载请带上原文链接,感谢
https://blog.csdn.net/HERODING23/article/details/124313428
边栏推荐
- How to open the developer tool when the uniapp runs to the built-in browser
- 内网即时通讯软件优点大全分享
- MySQL 视图(详解)
- MySQL MHA high availability cluster deployment and failover
- 静态链接与动态链接
- How does the national standard gb28181 platform easygbs turn on the voice intercom function?
- Alwaysinstallelevated
- Interpretation of YACs in detectron 2
- MySQL数据库索引面试题(最新版)
- Force buckle - 53 Maximum subarray sum
猜你喜欢

Overview of relational database and non relational database, introduction to redis, common commands and optimization

MySQL MHA高可用集群部署及故障切换

MySQL 视图(详解)

Automatic control principle Chapter 6 - correction and synthesis of control system (mind map)

Interviewer: a brief talk about go escape analysis?

机器学习笔记 - 迹算子(跟踪运算符)

switch分支

“最难就业季“中的大学生就业:本硕过半有着落 高职生成香饽饽

Low density lipoprotein research - LDL-C content detection kit scheme

MySQL数据库索引面试题(最新版)
随机推荐
[advanced C language] ⑥ detailed explanation of function pointer
Questions fréquemment incorrectes pour la certification quotidienne du CISSP (20 avril 2022)
Overview of relational database and non relational database, introduction to redis, common commands and optimization
Text to SQL learning and sorting (XVII) s2sql model
AAAI 2022 finer grained false information detection
The CPU and memory consumption are too high, but the memory and CPU occupied by the processes in the task manager cannot be seen
关于SQL语句的执行顺序
The fifth chapter uses Matplotlib to draw pie chart
Feign source code analysis
线程
Using MCU Xpress to develop rt1060 (1) -- drive RGB interface LCD
使用CMake构建/CMake命令参考
Abbexa donkey anti goat IgG (H & L) antibody
Interpretation of Chinese ner using lattice LSTM paper
学历造假、考试包过……考证市场有多乱
Big guys, why is it 10 times slower to call functions in this way?
【JZ47 礼物的最大价值】
Redis installation and configuration startup
第五章 使用 matplotlib 绘制饼图
AAAI 2022 更细粒度的不实信息检测