zoukankan      html  css  js  c++  java
  • leetcode824

    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;
        }
    };
  • 相关阅读:
    qbzt day6 上午
    qbzt day5 下午
    qbzt day5 上午
    【7.24校内交流赛】T3【qbxt】复读警告
    【7.24校内交流赛】T1&T2
    一个一定要好好提溜出来的贪心题
    7.19 讲题
    DP大大大大大赏
    图论经典例题大赏
    数据结构题大赏
  • 原文地址:https://www.cnblogs.com/asenyang/p/9723121.html
Copyright © 2011-2022 走看看