#include <iostream>
using namespace std;
int res[100005];
int main() {
int n, cnt = 0, pre;
cin >> n;
string kids;
cin >> kids;
for(int i = 0; i < n; i++){
if(kids[i] == '0') res[i] = i + 1;
else {
cnt++;
if(cnt >= 2)res[i] = pre;
pre = i + 1;
}
}
for(int i = 0; i < n; i++){
if(res[i])cout << res[i] << ' ';
else cout << pre << ' ';
}
}
// 64 位输出请用 printf("%lld")
首先安排不需要换座位的, 剩下就挨个顺移(利用pre), 然后最后没有填上座位的就直接输出pre(这样可以满足只有一个人不需要换座位时的情况, 不需要额外分类。

京公网安备 11010502036488号