#include#include#includeusing namespace std;int n,m;bool sor(int a,int b){if(abs(a%m)!=abs(b%m)){return a%m}if(a%2==1&&b%2==1){return a>b;}if(a%2==0&&b%2==0){return a}if(a%2!=b%2){return a%2==1;}}int main(){for(int i=0;i<20;i++){cin>>n>>m;if(n==0&&m==0){cout<<"0 0";return 0;}vector a(n);for(int j=0;jcin>>a[j];}sort(a.begin(),a.end(),sor);cout<for(int j:a){cout<}}return 0;}
Day1 #UVa 11321 & UVa 10041 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天 (ithome.com.tw)
#include "bits/stdc++.h"
using namespace std;
int n, m;
bool cmp(int i, int j) {
if (i % m != j % m) {
return i % m < j % m;
}
if ((i & 1) && (j & 1))
return i > j;
else if (!(i & 1) && !(j & 1))
return i < j;
else
return i & 1;
}
int main() {
while (cin >> n >> m, n) {
cout << n << " " << m << endl;
vector<int> nums(n);
for (auto& i : nums) {
cin >> i;
}
sort(nums.begin(), nums.end(), cmp);
for (auto& i : nums)
cout << i << endl;
}
cout << 0 << " " << 0 << endl;
}