package com.fishercoder.solutions;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * 824. Goat Latin
 *
 * A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.
 *
 * We would like to convert the sentence to "Goat Latin" (a made-up language similar to Pig Latin.)
 *
 * The rules of Goat Latin are as follows:
 *
 *     If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end of the word.
 *     For example, the word 'apple' becomes 'applema'.
 *
 *     If a word begins with a consonant (i.e. not a vowel), remove the first letter and append it to the end, then add "ma".
 *     For example, the word "goat" becomes "oatgma".
 *
 *     Add one letter 'a' to the end of each word per its word index in the sentence, starting with 1.
 *     For example, the first word gets "a" added to the end, the second word gets "aa" added to the end and so on.
 *
 * Return the final sentence representing the conversion from S to Goat Latin.
 *
 * Example 1:
 *
 * Input: "I speak Goat Latin"
 * Output: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"
 *
 * Example 2:
 *
 * Input: "The quick brown fox jumped over the lazy dog"
 * Output: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"
 *
 * Notes:
 *
 *     S contains only uppercase, lowercase and spaces. Exactly one space between each word.
 *     1 <= S.length <= 100.
 */
public class _824 {

  public static class Solution1 {
    public String toGoatLatin(String S) {
      StringBuilder sb = new StringBuilder();
      Set<Character> vowels =
          new HashSet(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
      String[] words = S.split(" ");
      for (int i = 0; i < words.length; i++) {
        if (vowels.contains(words[i].charAt(0))) {
          String newWord = words[i] + "ma";
          int j = i + 1;
          while (j-- > 0) {
            newWord += 'a';
          }
          sb.append(newWord);
          sb.append(" ");
        } else {
          StringBuilder subSb = new StringBuilder(words[i].substring(1));
          subSb.append(words[i].charAt(0));
          subSb.append("ma");
          int j = i + 1;
          while (j-- > 0) {
            subSb.append("a");
          }
          sb.append(subSb.toString());
          sb.append(" ");
        }
      }
      return sb.substring(0, sb.length() - 1);
    }
  }
}

@@ -107,1388 +107,8 @@
 t;%0A%0A
-/**%0A * 824. Goat Latin%0A *%0A * A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.%0A *%0A * We would like to convert the sentence to %22Goat Latin%22 (a made-up language similar to Pig Latin.)%0A *%0A * The rules of Goat Latin are as follows:%0A *%0A *     If a word begins with a vowel (a, e, i, o, or u), append %22ma%22 to the end of the word.%0A *     For example, the word 'apple' becomes 'applema'.%0A *%0A *     If a word begins with a consonant (i.e. not a vowel), remove the first letter and append it to the end, then add %22ma%22.%0A *     For example, the word %22goat%22 becomes %22oatgma%22.%0A *%0A *     Add one letter 'a' to the end of each word per its word index in the sentence, starting with 1.%0A *     For example, the first word gets %22a%22 added to the end, the second word gets %22aa%22 added to the end and so on.%0A *%0A * Return the final sentence representing the conversion from S to Goat Latin.%0A *%0A * Example 1:%0A *%0A * Input: %22I speak Goat Latin%22%0A * Output: %22Imaa peaksmaaa oatGmaaaa atinLmaaaaa%22%0A *%0A * Example 2:%0A *%0A * Input: %22The quick brown fox jumped over the lazy dog%22%0A * Output: %22heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa%22%0A *%0A * Notes:%0A *%0A *     S contains only uppercase, lowercase and spaces. Exactly one space between each word.%0A *     1 %3C= S.length %3C= 100.%0A */%0A
 publ
@@ -124,16 +124,18 @@
 _824 %7B%0A%0A
+  
   public
@@ -160,16 +160,20 @@
 tion1 %7B%0A
+    
     publ
@@ -202,24 +202,30 @@
 String S) %7B%0A
+      
       String
@@ -258,16 +258,22 @@
 lder();%0A
+      
       Se
@@ -294,16 +294,26 @@
 owels =%0A
+          
         
@@ -394,24 +394,30 @@
 U'));%0A      
+   
+   
 String%5B%5D wor
@@ -431,24 +431,30 @@
 split(%22 %22);%0A
+      
       for (i
@@ -496,16 +496,24 @@
         
+   
+     
 if (vowe
@@ -553,24 +553,34 @@
 %7B%0A          
+        
+  
 String newWo
@@ -601,16 +601,26 @@
 + %22ma%22;%0A
+          
         
@@ -638,32 +638,42 @@
  + 1;%0A          
+ 
+         
 while (j-- %3E 0) 
@@ -686,16 +686,28 @@
         
+    
+        
 newWord 
@@ -716,34 +716,54 @@
  'a';%0A          
+    
-%7D%0A
+      %7D%0A          
           sb.app
@@ -776,16 +776,26 @@
 wWord);%0A
+          
         
@@ -804,32 +804,40 @@
 sb.append(%22 %22);%0A
+        
         %7D else %7B
@@ -837,16 +837,26 @@
  else %7B%0A
+          
         
@@ -923,32 +923,42 @@
 (1));%0A          
+       
+   
 subSb.append(wor
@@ -971,24 +971,34 @@
 charAt(0));%0A
+          
           su
@@ -1011,24 +1011,34 @@
 pend(%22ma%22);%0A
+          
           in
@@ -1052,32 +1052,42 @@
  + 1;%0A          
+   
+       
 while (j-- %3E 0) 
@@ -1092,32 +1092,44 @@
 ) %7B%0A            
+      
+      
 subSb.append(%22a%22
@@ -1133,34 +1133,54 @@
 %22a%22);%0A          
+      
-%7D%0A
+    %7D%0A          
           sb.app
@@ -1198,24 +1198,34 @@
 oString());%0A
+          
           sb
@@ -1246,24 +1246,46 @@
         
+ 
+       %7D%0A            
 %7D%0A      
 %7D%0A      
@@ -1272,26 +1272,24 @@
     %7D%0A      
-%7D%0A
       return
@@ -1327,16 +1327,22 @@
 1);%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 824