#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; // 排列的长度 string s; // 输入的01字符串 cin >> n; cin >> s; vector<int> res; // 用于存储最终的排列 if(s[n-1] == '0'){ // 如果字符串的最后一个字符是'0' cout << -1 << endl; // 直接输出-1,因为整个排列无法构成一个排列 return 0; } // 初始化排列为1到n的顺序排列 for(int i = 0; i < n; ++i){ res.emplace_back(i + 1); // 将i+1加入到排列中 } // 遍历字符串s for(int i = 0; i < n; ++i){ if(s[i] == '0'){ // 如果当前字符是'0' swap(res[i], res[i + 1]); // 交换当前元素和下一个元素 } cout << res[i] << ' '; // 输出当前元素 } return 0; }