题解 | 小欧安排座位

小欧安排座位

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

//  #牛客春招刷题训练营# https://www.nowcoder.com/discuss/726480854079250432
//  让不特别的小朋友做自己的位置,特别的小朋友顺时针换位一次(实现:先把特别的小朋友的作为push到一个vector中,同过索引输出)。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  string s;
  int n, index = 1;
  cin >> n >> s;
  vector<int> rest;
  for (int i = 0; i < n; i++)
    if (s[i] == '1'){
      rest.push_back(i + 1);
    }
  size_t size = rest.size();
  for (int i = 0; i < n; i++){
    if (s[i] == '0'){
      cout << i + 1 << ' ';
    }
    else{
      if (index == size) index = 0;
      cout << rest[index] << ' ';
      index++;
    }
  }
  return 0;
}

#写题解领奖励##牛客春招刷题训练营#
全部评论

相关推荐

04-03 12:09
東京大学 C++
求求求求暑期offer:留第一行,剩下的不要
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务