关注
两种情况分开处理,可以通过全部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; }
查看原帖
点赞 1
相关推荐
牛客热帖
更多
正在热议
更多
# 2025年终总结 #
123801次浏览 2078人参与
# 实习简历求拷打 #
16561次浏览 194人参与
# 作业帮求职进展汇总 #
83973次浏览 554人参与
# 秋招被挂春招仍然能投的公司 #
7764次浏览 108人参与
# 实习要如何选择和准备? #
128543次浏览 1486人参与
# 外包能不能当跳板? #
54281次浏览 256人参与
# 诺瓦星云求职进展汇总 #
233511次浏览 1736人参与
# mt对你说过最有启发的一句话 #
38995次浏览 454人参与
# 公司情报交流地 #
126685次浏览 1227人参与
# 为了找工作你花了哪些钱? #
74885次浏览 361人参与
# 你觉得机械有必要实习吗 #
69854次浏览 485人参与
# 投格力的你,拿到offer了吗? #
153428次浏览 822人参与
# 一起聊美团 #
307647次浏览 1767人参与
# 什么是优秀的实习经历 #
9377次浏览 226人参与
# 摸鱼被leader发现了怎么办 #
103830次浏览 659人参与
# 京东开奖 #
632062次浏览 3180人参与
# 秋招特别不鸣谢 #
16600次浏览 186人参与
# 考研失败就一定是坏事吗? #
202601次浏览 1387人参与
# 选实习,你更看重哪方面? #
15292次浏览 230人参与
# 安克创新求职进展汇总 #
62474次浏览 541人参与
