#include <iostream>
#include <string>
using namespace std;

string getSmallestString(string s) {
    int n = s.size();
    string t = s;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') {
            int j = i + 1;
            while (j < n && s[j] == '1') {
                j++;
            }
            reverse(t.begin() + i, t.begin() + j);
            i = j - 1;
        }
    }
    return t;
}

int main() {
    string s;
    cin >> s;
    string ans = getSmallestString(s);
    cout << ans << endl;
    return 0;
}
``
# 扶苏和串## 题目背景众所周知每个月入门赛的字符串题都是扶苏来枚举 idea 出出来的。## 题目描述给定一个 01 字符串 $s$你可以任选 $s$ 的一个非空子串把这个子串在 $s$ 中翻转一次。问你能得到字典序最小的字符串是什么?形式化的你可以选择一个区间 $l r$ 满足 $1 leq l leq r leq s$构造一个串 $t$ 满足:$$t_i = begincasess_i &

原文地址: https://www.cveoy.top/t/topic/h4pr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录