special show

题目描述
从前,算了,不编故事背景了。
有n个数,排序。每个数a[i]先对k取余,结果大的排前面。如果结果相同,根据原来的数,从小到大排。

输入格式
第一行一个数字t,表示测试数据的组数。
对于每组测试数据,包括两行,第一行两个数n和k;第二行n个正整数。

输出格式
每组测试数据输出一行,为排序之后的结果

样例输入
1
5 2
9 2 6 8 3

样例输出
3 9 2 6 8

提示
t<=30
n<=10000
k<=100
a[i]< max int

#include<iostream>
#include<algorithm>
using namespace std;
int a[10005];
int t,n,k;
bool cmp(int x,int y){
    
    
	if(x%k!=y%k)	return x%k>y%k;
	return x<y;
}
int main(){
    
    
	
	cin>>t;
	while(t--){
    
    
		cin>>n>>k;
		for(int i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n,cmp);
		for(int i=0;i<n;i++)
			cout<<a[i]<<" ";
		cout<<endl;
	}
	cout<<endl;	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_51794965/article/details/110109182