1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 19:18:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/山羊拉丁文 [goat-latin].html
2022-03-29 12:43:11 +08:00

40 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个由空格分割单词的句子&nbsp;<code>S</code>。每个单词只包含大写或小写字母。</p>
<p>我们要将句子转换为&nbsp;<em>&ldquo;Goat Latin&rdquo;</em>(一种类似于 猪拉丁文&nbsp;- Pig Latin 的虚构语言)。</p>
<p>山羊拉丁文的规则如下:</p>
<ul>
<li>如果单词以元音开头a, e, i, o, u在单词后添加<code>&quot;ma&quot;</code><br />
例如,单词<code>&quot;apple&quot;</code>变为<code>&quot;applema&quot;</code></li>
<br />
<li>如果单词以辅音字母开头(即非元音字母),移除第一个字符并将它放到末尾,之后再添加<code>&quot;ma&quot;</code><br />
例如,单词<code>&quot;goat&quot;</code>变为<code>&quot;oatgma&quot;</code></li>
<br />
<li>根据单词在句子中的索引,在单词最后添加与索引相同数量的字母<code>&#39;a&#39;</code>索引从1开始。<br />
例如,在第一个单词后添加<code>&quot;a&quot;</code>,在第二个单词后添加<code>&quot;aa&quot;</code>,以此类推。</li>
</ul>
<p>返回将&nbsp;<code>S</code>&nbsp;转换为山羊拉丁文后的句子。</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入: </strong>&quot;I speak Goat Latin&quot;
<strong>输出: </strong>&quot;Imaa peaksmaaa oatGmaaaa atinLmaaaaa&quot;
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入: </strong>&quot;The quick brown fox jumped over the lazy dog&quot;
<strong>输出: </strong>&quot;heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa&quot;
</pre>
<p><strong>说明:</strong></p>
<ul>
<li><code>S</code>&nbsp;中仅包含大小写字母和空格。单词间有且仅有一个空格。</li>
<li><code>1 &lt;= S.length &lt;= 150</code></li>
</ul>