knakul853

Untitled

Jun 20th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4.  
  5. class Solution {
  6. public:
  7.     string toGoatLatin(string S) {
  8.        
  9.       stringstream in(S), out;
  10.        
  11.        
  12.         string word, vowels("aeiouAEIOU");
  13.         string a;
  14.         while( in >> word )
  15.         {
  16.             a.push_back('a');
  17.             if( vowels.find(word[0])!=string::npos) // vowels
  18.             {
  19.                
  20.                 out <<" "<< word<<"ma"<<a;
  21.             }
  22.             else{
  23.                 out <<" "<<word.substr(1)<<word[0]<<"ma"<<a;
  24.             }
  25.         }
  26.        
  27.         return out.str().substr(1);
  28.        
  29.     }
  30. };
Add Comment
Please, Sign In to add comment