【Leetcode_easy】824. Goat Latin

problem

824. Goat Latin

solution

class Solution {
public:
    string toGoatLatin(string S) {
        unordered_set<char> vowel{ 'a', 'e', 'i', 'o', 'u', 
                                  'A', 'E', 'I', 'O', 'U' };//
        istringstream iss(S);//
        string res, word;
        int cnt = 1;
        while(iss >> word)
        {
            res += ' ' + (vowel.count(word[0]) ? word : word.substr(1)+word[0]) + "ma" + string(cnt, 'a');//err...
            cnt++;
        }
        return res.substr(1);//err....      
    }
};

参考

1. Leetcode_easy_824. Goat Latin;

2. grandyang;

3. discuss;

原文地址:https://www.cnblogs.com/happyamyhope/p/11214820.html