-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0824-Goat-latin.cs
More file actions
38 lines (32 loc) · 1.02 KB
/
0824-Goat-latin.cs
File metadata and controls
38 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Text;
namespace Solution._0824.Goat_latin
{
public class _0824_Goat_latin
{
public string ToGoatLatin(string sentence)
{
StringBuilder sb = new StringBuilder();
string[] s = sentence.Split(" ");
for (int i = 0; i < s.Length; i++)
{
if (s[i].ToLower().StartsWith("a") || s[i].ToLower().StartsWith("e") || s[i].ToLower().StartsWith("i") || s[i].ToLower().StartsWith("o") || s[i].ToLower().StartsWith("u"))
{
sb.Append(s[i]);
sb.Append("ma");
}
else
{
sb.Append(s[i].Substring(1));
sb.Append(s[i][0]);
sb.Append("ma");
}
for (int j = 0; j < i + 1; j++)
sb.Append("a");
sb.Append(" ");
}
return sb.ToString().TrimEnd();
}
}
}