当前位置:网站首页>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
边栏推荐
- Heap overflow of kernel PWN basic tutorial
- Kubernetes cluster installation based on Kirin SP10 server version
- Hyperscan -- 2 compilation
- Esp32 message queue using FreeRTOS
- 每日一题(2022-04-22)——旋转函数
- NPM yarn startup error [resolved]
- Thinkphp内核开发盲盒商城源码v2.0 对接易支付/阿里云短信/七牛云存储
- 关于局域网浅谈
- Introduction to esp32 Bluetooth controller API
- Realize linear regression with tensorflow (including problems and solutions in the process)
猜你喜欢

使用代理IP是需要注意什么?

Esp32 message queue using FreeRTOS

拨号服务器是什么,有什么用处?

89 logistic回歸用戶畫像用戶響應度預測

How to initialize "naming and surname" in C language

BGP服务器在什么业务场景会被用到?

Shardingsphere read write separation

89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur

Some tips for using proxy IP.

Batch multiple files into one hex
随机推荐
PHP & laravel & master several ways of generating token by API and some precautions (PIT)
What are the test steps of dynamic proxy IP?
easyswoole环境配置
【Chrome扩展程序】content_script的跨域问题
简洁开源的一款导航网站源码
C standard library - < time h>
Quel est le fichier makefile?
Hyperscan -- 2 compilation
Micro build low code zero foundation introductory course
什么是api接口?
007_Redis_Jedis连接池
How to write the resume of Software Test Engineer so that HR can see it?
Why is one plus one equal to two
Lane cross domain problem
tp6阿里云短信 window 报 cURL error 60: SSL certificate problem: unable to get local issuer certificate
89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur
013_基于Session实现短信验证码登录流程分析
我国科学家揭示突破水稻产量瓶颈新机制
What is a dial-up server and what is its use?
拨号服务器是什么,有什么用处?