The problem : 1605B - Reverse Sort
This problem has $$$2$$$ traditions.
- This array had already been sorted.
Now the $$$m$$$ is $$$0$$$.
- This array had not been sorted.
The $$$m$$$ is $$$1$$$.
Make $$$k$$$ is the number of 1s.
if has one $$$i(0<i<n+1):$$$
$$$s_i=1\ and\ i<n-k+1 : $$$ We need to add $$$i$$$ to ans.
$$$s_i=0\ and\ i>n-k : $$$ We need to add $$$i$$$ to ans, too.
The code is very short:
#include <bits/stdc++.h>
using namespace std;
char s[1005];
int n;
int a[1005];
signed main () {
int t;
cin >> t;
while (t --) {
cin >> n >> s + 1;
int is = 0;
for (int i = 1;i <= n; ++ i) {
if (s[i] == '1') is ++;
}
int cnt = 0;
memset (a, 0, sizeof a);
for (int i = 1;i <= n; ++ i) {
if (s[i] == '1' && i <= n - is) a[++ cnt] = i;
if (s[i] == '0' && i > n - is) a[++ cnt] = i;
}
if (cnt == 0) cout << 0 << endl;
else {
cout << 1 << endl;
cout << cnt << ' ';
for (int i = 1;i <= cnt; ++ i) {
cout << a[i] << ' ';
}
cout << endl;
}
}
return 0;
}
Auto comment: topic has been updated by WaterGroup (previous revision, new revision, compare).