題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=show_problem&problem=2296
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include <iostream> #include <algorithm>
using namespace std;
int n, m;
bool cmp(int x, int y){ if((x%m) != (y%m)) return (x%m) < (y%m); if(x%2 == 1 && y%2 == 1) return x > y; if(x%2 == 0 && y%2 == 0) return x < y; else return x%2; }
int main(){ while(cin >> n >> m){ cout << n << ' ' << m << '\n'; if(n == 0 && m == 0) break; int arr[n] = {}; for(int i=0; i<n; ++i) cin >> arr[i]; sort(arr, arr+n, cmp); for(int i=0; i<n; ++i) cout << arr[i] << '\n'; } return 0; }
|