葉林
Linked with GitHub
# LeetCode - 0824. Goat Latin ### 題目網址:https://leetcode.com/problems/goat-latin/ ###### tags: `LeetCode` `Easy` `字串` ```cpp= /* -LeetCode format- Problem: 824. Goat Latin Difficulty: Easy by Inversionpeter */ class Solution { bool IsVowel(char c) { c = tolower(c); return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); } public: string toGoatLatin(string S) { int last = 0; string suffix = "a", answer = ""; for (int i = 0; i != S.size(); ++i) if (S[i] == ' ') { answer += (IsVowel(S[last]) ? S.substr(last, i - last) : S.substr(last + 1, i - last - 1) + S[last]) + "ma" + suffix + ' '; suffix += 'a'; last = i + 1; } answer += (IsVowel(S[last]) ? S.substr(last) : S.substr(last + 1) + S[last]) + "ma" + suffix; return answer; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up