首页 > 其他 > 详细

In a Line

时间:2014-02-18 16:12:39      阅读:346      评论:0      收藏:0      [点我收藏+]

Description

There are n (2<=n<=50) integers. Arrange them in a row so that the maximal difference between adjacent numbers is minimal.

Input

The first line contains one integer, indicating the number of test cases. For each test case, there is one line containing the n numbers.

Output

Output one line for each test case containing an arrangement of the numbers which minimizes the maximal difference. Numbers should be separated by one space. If there are several arrangements that meet the requirement, output the lexicographically smallest one.

Sample Input

2
5 1 3
1 8 2 4

Sample Output

1 3 5
1 2 4 8
参考代码如下:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
char ch;
int i,t,d[55];
scanf("%d",&t);
getchar();
while(t--)
{
memset(d,0,sizeof(d));
i=0;
ch=getchar();
while(1)
{
d[i]=0;
if(ch==‘\n‘||ch==EOF) break;
while(ch==‘ ‘) ch=getchar();
while(isalnum(ch))
{
d[i]=d[i]*10+ch-‘0‘;
ch=getchar();
}
i++;
}
if(ch==EOF) break;
sort(d,d+i);
for(int j=0;j<i-1;j++)
printf("%d ",d[j]);
printf("%d\n",d[i-1]);
}
return 0;
}

In a Line

原文:http://blog.csdn.net/u011292087/article/details/19400749

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!