题目1117:整数奇偶排序

来源:互联网 发布:cdma是什么网络 编辑:程序博客网 时间:2024/05/01 17:27
#include <vector>#include <iostream>#include <fstream>#include <algorithm>using namespace std;bool cmp(const int a, const int b);int main(){#ifndef ONLINE_JUDGEifstream cin("d:\\OJ\\uva_in.txt");#endifvector<int> v(10);while (cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4] >> v[5] >> v[6] >> v[7] >> v[8] >> v[9]) {sort(v.begin(), v.end(), cmp);bool first = true;for (int i = 0; i < 10; i++) {if (first) first = false;else cout << " ";cout << v[i];}cout << endl;}return 0;}bool cmp(const int a, const int b){if ((a & 1) && !(b & 1)) return true;else if (!(a & 1) && (b & 1)) return false;else if ((a & 1) && (b & 1)) return a > b;else return a < b;}

0 0
原创粉丝点击