#include<memory> #include<string> #include<iostream> #include<vector> using namespace std; int code(string s) {     if (s.size() < 4)         return s.size();     vector<pair<string, int>> k;     for (size_t i = 1; i <= s.size() / 2; i++) {         string tmp(s.begin(), s.begin() + i);         k.push_back(make_pair(tmp, 1));     }     for (auto it = k.begin(); it != k.end(); it++) {         size_t len = (it->first).size();         for (size_t m = len; m+len<s.size()+1; m += len) {             string tmp(s.begin() + m, s.begin() + m + len);             if (it->first == tmp)                 it->second++;             else                 break;         }     }     auto max_index = k.end();     size_t max = 0;     for (auto it = k.begin(); it != k.end(); it++) {         if (it->second >= 2) {             size_t len = ((it->first).size())*(it->second);             if (len > max && (len > (it->first).size() + 3)) {                 max_index = it;                 max = len;             }         }     }     if (max_index != k.end()) {         string tmp(s.begin() + max, s.end());         return (code(max_index->first) + 3 + code(tmp));     }     else {         string tmp(s.begin() + 1, s.end());         return (1 + code(tmp));     }     return s.size(); } int main() {     string in;     cin >> in;     cout << code(in);     return 0; }
点赞 评论

相关推荐

昨天 09:08
裁应届生,一分钱补偿没有,离职了还脑控你,跟踪你,定位你,丁东服务是搞系每一个人
牛客吹哨人:建议细说...哨哥晚点统一更新到黑名单:不要重蹈覆辙!25届毁意向毁约裁员黑名单https://www.nowcoder.com/discuss/1317104
叮咚买菜稳定性 9人发布 投递叮咚买菜等公司10个岗位 >
点赞 评论 收藏
分享
牛客网
牛客企业服务