# 824.Goat Latin

**824.Goat Latin**

难度:Easy

> 给定一个由空格分割单词的句子 S。每个单词只包含大写或小写字母。

我们要将句子转换为 “Goat Latin”（一种类似于 猪拉丁文 - Pig Latin 的虚构语言）。

山羊拉丁文的规则如下：

如果单词以元音开头（a, e, i, o, u），在单词后添加"ma"。 例如，单词"apple"变为"applema"。

如果单词以辅音字母开头（即非元音字母），移除第一个字符并将它放到末尾，之后再添加"ma"。 例如，单词"goat"变为"oatgma"。

根据单词在句子中的索引，在单词最后添加与索引相同数量的字母'a'，索引从1开始。 例如，在第一个单词后添加"a"，在第二个单词后添加"aa"，以此类推。 返回将 S 转换为山羊拉丁文后的句子。

```
示例 1:

输入: "I speak Goat Latin"
输出: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"
示例 2:

输入: "The quick brown fox jumped over the lazy dog"
输出: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"
说明:

S 中仅包含大小写字母和空格。单词间有且仅有一个空格。
1 <= S.length <= 150。
```

方法： 使用集合判断是否是元音字符。

```
class Solution {
private:
    unordered_set<char>ma={'a','e','i','o','u','A','E','I','O','U'};
public:
    string toGoatLatin(string S) {
        vector<string> tmp;
        string t;
        for(auto i: S)
        {
            if(i==' ')
            {
                tmp.push_back(t);
                t="";
            }
            else
                t+=i;
        }
        tmp.push_back(t);
        for(int i=0;i<tmp.size();i++)
        {
            if(ma.count(tmp[i][0]))
                tmp[i]=tmp[i]+"ma";
            else
            {
                tmp[i]=tmp[i].substr(1) +tmp[i][0]+"ma";
            }
            int n=i+1;
            while(n-- >0)
            {
                tmp[i] +="a";
            }
        }
        t="";
        for(int i=0;i<tmp.size()-1;i++)
            t+=tmp[i]+" ";
        t+=tmp[tmp.size()-1];
        return t;
        
    }
};
```

> 执行用时 : 8 ms, 在Goat Latin的C++提交中击败了95.14% 的用户\
> 内存消耗 : 9.5 MB, 在Goat Latin的C++提交中击败了56.52% 的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/824.goat_latin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
