本文主要是介绍今日学习在线编程题:波兰国旗问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目来源:码蹄集
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;
}
这篇关于今日学习在线编程题:波兰国旗问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!