题面
对 个正整数组成的数组按以下顺序排序:
按正整数二进制表示中1
的位数的降序排序,1
的位数相同的数按数本身值的升序排序。
使用 qsort
定义函数 Sort
//********** Specification of Sort **********
void Sort(unsigned *p, unsigned n);
/* PreCondition:
p points to an array with n unsigned integers
PostCondition:
array is sorted satisfying to the specification
*/
main
函数如下:
int main()
{ unsigned n,i,a[1000]; scanf("%u",&n);
for (i=0;i<n;i++) scanf("%u",a+i); Sort(a,n);
for (i=0;i<n;i++) printf("%u%c",a[i],i!=n-1?' ':'\n');
return 0;
}
输入格式
第1行是一个整数
第2行是用一个空格分隔的 个 unsigned
类型正整数
输出格式
输出排序后的数。格式参照 main
函数。
样例
输入
2 1 2
输出
1 2
输入
2 10 7
输出
7 10
输入
3 1 2 3
输出
3 1 2