题解 | 小欧安排座位
小欧安排座位
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; }#写题解领奖励##牛客春招刷题训练营#