不独特的人就不独特,直接输出,而独特的人就让他们去坐下一个独特的人的座位就可以了,最后一个独特的人坐第一个人的位置。

#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <numeric>
#include <ctime>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
const ll N = 1e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;

int n, a[N];

void solve() {
    cin >> n;
    string s;
    cin >> s;

    map<int, int>mp;
    vector<int>ve;

    for (int i = 0; i < n; i++) {
        if (s[i] == '0')a[i + 1] = i + 1;
        else {
            ve.push_back(i + 1);
        }
    }

    for (int i = 0; i < ve.size() - 1; i++) {
        mp[ve[i]] = ve[i + 1];
    }
    mp[ve.back()] = ve[0];

    for (int i = 1; i <= n; i++) {
        cout << (a[i] ? a[i] : mp[i]) << " ";
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;
    //cin>>t;

    while (t--) {

        solve();

    }

    return 0;
}