标签:begin else amp str turn tst int tor div
class Solution { public: void SplitString(const string& s, vector<string>& v, const string& c) { string::size_type pos1, pos2; pos2 = s.find(c); pos1 = 0; while (string::npos != pos2) { v.push_back(s.substr(pos1, pos2 - pos1)); pos1 = pos2 + c.size(); pos2 = s.find(c, pos1); } if (pos1 != s.length()) v.push_back(s.substr(pos1)); } string toGoatLatin(string S) { vector<string> V; SplitString(S, V, " "); set<char> ST; ST.insert(‘a‘); ST.insert(‘e‘); ST.insert(‘i‘); ST.insert(‘o‘); ST.insert(‘u‘); ST.insert(‘A‘); ST.insert(‘E‘); ST.insert(‘I‘); ST.insert(‘O‘); ST.insert(‘U‘); string Result = ""; for (int i = 0; i < V.size(); i++) { string word = V[i]; char begin = word[0]; string newword = ""; if (ST.find(begin) != ST.end())//元音 { newword = word + "ma"; } else//辅音 { string a = word.substr(1); string b = word.substr(0, 1); newword = a + b + "ma"; } for (int j = 0; j <= i; j++) { newword += "a"; } Result += newword; if (i != V.size() - 1) { Result += " "; } } return Result; } };
标签:begin else amp str turn tst int tor div
原文地址:https://www.cnblogs.com/asenyang/p/9723121.html