题解 | #整数奇偶排序#
整数奇偶排序
http://www.nowcoder.com/practice/bbbbf26601b6402c9abfa88de5833163
速度渣渣的好懂方法,vector容器
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ vector<int>jishu; vector<int>oshu; for (int i=0; i<10; i++){ int x; cin>>x; if (x%2 == 1) jishu.push_back(x); else oshu.push_back(x); } sort(jishu.rbegin(), jishu.rend()); sort(oshu.begin(), oshu.end()); for (unsigned int i=0; i<jishu.size();++i) cout<<jishu[i]<<" "; for (unsigned int i=0; i<oshu.size();++i) cout<<oshu[i]<<" "; cout<<endl; return 0; }