两种情况分开处理,可以通过全部case,不能递归,用递归开销太大,用递归就输了
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    int n = 0;
    cin >> n;
    string strIn;
    string strTmp;
    string strOut;
    vector<string> vStr, vRes;
    while (n--)
    {
        cin >> strIn;
        vStr.push_back(strIn);
    }
    for (int i = 0; i < vStr.size(); i++)
    {
        strTmp = vStr[i];

        int k = 0;
        while (k < strTmp.length())
        {
            ////////////////////////////////
            string str3;
            str3 += strTmp[k];
            str3 += strTmp[k];
            str3 += strTmp[k];

            int nIdx = strTmp.find(str3);
            if (-1 == nIdx)
            {
                k += 1;
                continue;
            }
            else
            {
                strOut += strTmp.substr(0, nIdx);
                strOut += strTmp[k];
                strOut += strTmp[k];
                strOut += strTmp.substr(nIdx + 3, strTmp.length());
                strTmp = strOut;
                strOut.clear();
            }
            //////////////////////////
        }
        int h = 0;
        strOut.clear();
        while (h < strTmp.length())
        {
            if (h + 3 < strTmp.length())
            {
                string str2;
                if ((strTmp[h] == strTmp[h + 1]) && (strTmp[h + 2] == strTmp[h + 3]))
                {
                    str2 += strTmp[h];
                    str2 += strTmp[h + 1];
                    str2 += strTmp[h + 2];
                    str2 += strTmp[h + 3];

                    int nIdx = strTmp.find(str2);
                    strOut += strTmp.substr(0, nIdx);
                    strOut += strTmp[h];
                    strOut += strTmp[h + 1];
                    strOut += strTmp[h + 2];
                    strOut += strTmp.substr(nIdx + 4, strTmp.length());
                    strTmp = strOut;
                    strOut.clear();
                }
            }
            h += 1;
        }
        vRes.push_back(strTmp);
    }
    for (int i = 0; i < vRes.size(); i++)
    {
        cout << vRes[i] << endl;
    }
    system("pause");
    return 0;
}