#include <iostream>#include <string>#include <vector>using namespace std;void solve(std::string& s){ if (s.size() <= 2) return; std::string ret; ret = s[0]; int count = 1; int flag = 0;//0代表第一个无重复,1代表AA,2代表AAB,3代表AAA,4代表AABB; for (int i = 1; i < s.size(); i) { if (s[i] != s[i - 1]) { flag = (flag == 1) ? 2 : 0; } else { switch (flag) { case 0:flag = 1; break; case 1:flag = 3; break; case 2:flag = 4; break; } } switch(flag) { case 0:ret = s[i]; break; case 1:ret = s[i]; break; case 2:ret = s[i]; break; case 3:flag = 1; break; case 4:flag = 2; break; default:break; } } s = ret;}int main(){ int n; cin >> n; vector<string> temp(n); for (int i = 0; i < n; i) { cin >> temp[i]; solve(temp[i]); } for (auto s : temp) { std::cout << s << std::endl; } return 0;}基于有限状态机
点赞 评论

相关推荐

不愿透露姓名的神秘牛友
11-05 12:57
已编辑
思朗 处理器 N+8 公积金12 硕士985
点赞 评论 收藏
分享
牛客网
牛客企业服务