-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoatLatin.java
More file actions
51 lines (43 loc) · 1.12 KB
/
GoatLatin.java
File metadata and controls
51 lines (43 loc) · 1.12 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
39
40
41
42
43
44
45
46
47
48
49
50
51
package Leetcode;
import java.util.HashSet;
import java.util.Scanner;
public class GoatLatin
{
public static void main( String[] args )
{
Scanner s = new Scanner( System.in );
String str = s.nextLine();
String res = toGoatLatin( str );
System.out.println( res );
}
public static String toGoatLatin( String S )
{
HashSet<Character> vowels = new HashSet<Character>();
for(Character c: "aeiouAEIOU".toCharArray())
{
vowels.add( c );
}
int index =1;
String res = new String();
for(String word: S.split( " " ))
{
if(index>1)
res+=" ";
char firstLetter = word.charAt( 0 );
if(vowels.contains( firstLetter ))
{
res+=word+"ma";
}
else
{
res+=word.substring( 1 )+firstLetter+"ma";
}
for(int i=0;i<index;i++)
{
res+="a";
}
index++;
}
return res;
}
}