Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct data
- {
- long long val;
- long long mod;
- } arr[10005];
- long long m;
- bool cmp(data l,data r)
- {
- if(l.mod==r.mod)
- {
- long long a = abs(l.val)%2;
- long long b = abs(r.val)%2;
- if(a==1 && b==1)
- {
- return l.val>r.val;
- }
- else if(a==0 && b==0)
- {
- return l.val<r.val;
- }
- else
- {
- if(a==0 && b==1)
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
- }
- else
- {
- return l.mod<r.mod;
- }
- }
- int main()
- {
- long long n,i;
- while(scanf("%lld%lld",&n,&m)==2)
- {
- if(n==0 && m==0)
- {
- printf("0 0\n");
- break;
- }
- for(i=1; i<=n; i++)
- {
- scanf("%lld",&arr[i].val);
- arr[i].mod = arr[i].val%m;
- }
- sort(arr+1,arr+n+1,cmp);
- printf("%lld %lld\n",n,m);
- for(i=1; i<=n; i++)
- {
- printf("%lld\n",arr[i].val);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment