当前位置:网站首页>Latin goat (20204-2022) - daily question 1
Latin goat (20204-2022) - daily question 1
2022-04-23 02:08:00 【Fill your head with water】
824. Goat Latin
Title Description :
Give you a sentence consisting of several words sentence , Words are separated by spaces . Each word consists only of uppercase and lowercase letters .
Please translate the sentence into “ Goat Latin (Goat Latin, Return to sentence Sentence after conversion to goat Latin .
The rules of goat Latin are as follows :
- If the word begins with a vowel (‘a’, ‘e’, ‘i’, ‘o’, ‘u’), Add... After the word "ma".
- for example , word “apple” Turn into “applema” .
- If the word begins with a consonant ( namely , Non vowel letter ), Remove the first character and put it at the end , Then add "ma".
- for example , word “goat” Turn into “oatgma” .
- According to the index of words in sentences , Add at the end of the word the same number of letters as the index ’a’, Index from 1 Start .
- for example , Add... After the first word “a” , Add... After the second word “aa” , And so on .
Example 1:
Input :sentence = “I speak Goat Latin”
Output :“Imaa peaksmaaa oatGmaaaa atinLmaaaaa”
Example 2:
Input :sentence = “The quick brown fox jumped over the lazy dog”
Output :“heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa”
Answer key :
func toGoatLatin(sentence string) string {
assistStr := "aeiouAEIOU"
words := strings.Split(sentence, " ")
ansSlice:=make([]string,len(words))
// Traverse words, Corresponding i, It is also after the change word stay ansSlice Position in slice
for i, word := range words {
index := i + 1
if strings.Contains(assistStr, string(word[0])) {
word = addA(word+"ma", index)
ansSlice[i] = word
continue
} else {
word = addA(word[1:]+string(word[0])+"ma", index)
ansSlice[i] = word
continue
}
}
return strings.Join(ansSlice," ")
}
// word After adding a,index How much is the , Add several “a”
func addA(word string, index int) string {
for i := 0; i < index; i++ {
word = word + "a"
}
return word
}
Submit results :
版权声明
本文为[Fill your head with water]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230206063809.html
边栏推荐
- 006_redis_SortedSet类型
- Realize linear regression with tensorflow (including problems and solutions in the process)
- Esp32 message queue using FreeRTOS
- Implementation of Base64 encoding / decoding in C language
- What are the test steps of dynamic proxy IP?
- Batch multiple files into one hex
- World Book Day 𞓜 a good book that technicians should not miss (it cutting-edge technology)
- 89 logistic回歸用戶畫像用戶響應度預測
- 89 logistic regression user portrait user response prediction
- openstack 服务的启动
猜你喜欢
Micro build low code zero foundation introductory course
Leetcode40 - total number of combinations II
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
How to write the resume of Software Test Engineer so that HR can see it?
002_Redis_String类型常见的操作命令
NPM yarn startup error [resolved]
Analyze the three functions of static proxy IP.
搭建个人主页保姆级教程(二)
[assembly language] understand "stack" from the lowest point of view
Dynamic memory management
随机推荐
Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy
89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur
Analyze the three functions of static proxy IP.
代理IP可用率是不是等同于代理IP的效率?
How to set computer IP?
Shardingsphere introduction and sub table usage
Shardingsphere read write separation
How to classify proxy IP?
EBS:PO_EMPLOYEE_HIERARCHIES_ALL
go语言打怪通关之 ⌈互斥锁和状态协程⌋
011_RedisTemplate操作Hash
Why is one plus one equal to two
Is the availability of proxy IP equal to the efficiency of proxy IP?
006_redis_jedis快速入门
Leetcode39 combined sum
简洁开源的一款导航网站源码
Unity editor hierarchy drop-down menu extension
Startup of openstack service
在使用代理IP前需要了解哪些分类?
Use Xdebug breakpoint debugging in postman