题解 | 小红的排列构造

小红的排列构造

https://www.nowcoder.com/practice/a4ec29e74aaa450aa8a4200fe3b06308

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

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    vector<int> res;
    if(s[n-1] == '0'){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0; i<n; ++i){
        res.emplace_back(i+1);
    }
    for(int i=0; i<n; ++i){
        if(s[i]=='0'){
            swap(res[i], res[i+1]);
        }
        cout << res[i] << ' ';
    }

    return 0;

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

12-22 16:31
已编辑
桂林电子科技大学 Python
很奥的前端仔:如果你接了offer 临时又说不去 hr确实要多做一些工作。 当然如果是接offer之前当我没说
点赞 评论 收藏
分享
做黑夜里的那道光:两年电赛完赛没必要写,纯扣分
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务