题目来源:码蹄集
https://matiji.net/exam/brushquestion/326/778/B3FCFEC101BD05189BB74D522E019504
参考程序:
#include <iostream>
#define N 10000
int main() {
char s[N];
int n;
scanf("%d", &n);
scanf("%s", s);
int high = n-1, low = 0;
while(high > low) {
if (s[low] == '0' && s[high] == '0') {
++low;
} else if (s[low] == '1' && s[high] == '1') {
--high;
} else if (s[low] == '1' && s[high] == '0') {
char tmp = s[low];
s[low] = s[high];
s[high] = tmp;
--high;
++low;
} else{
--high;
++low;
}
}
printf("%s\n", s);
return 0;
}