In a Line
来源:互联网 发布:全球经济数据网 编辑:程序博客网 时间:2024/06/06 18:56
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
25 1 31 8 2 4
Sample Output
1 3 51 2 4 8
¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
要注意结束以‘\n’,注意和字符的交配使用;
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int g[100000];
int i,j,k,ncase,m,n;
scanf("%d",&ncase);
while(ncase--)
{
char c;i=0;
while(scanf("%d%c",&g[i++],&c)!=EOF)
{
if(c=='\n')
break;
}
sort(g,g+i);
printf("%d",g[0]);
for(j=1;j<i;j++)
printf(" %d",g[j]);
printf("\n");
}
return 0;
}
- In a Line
- In a Line
- Coins in a Line
- Boxes in a Line
- coins in a line
- Coins in a Line
- Stand in a Line UVA11174
- UVA11174 Stand in a Line
- 12657-Boxes in a Line
- UVa12657 Boxes in a Line
- uva12657 boxes in a line
- 12657 Boxes in a Line
- lintcode:Coins in a Line
- [LintCode]Coins in a Line
- uva12657 Boxes in a Line
- 12657 - Boxes in a Line
- Uva12657 Boxes in a line
- #394 Coins in a Line
- 常用Sql 记录
- 关于List中引用的问题
- Linux设备驱动工程师之路——设备模型(上)底层模型
- Jsp内置对象使用
- MFC界面编程2011年9月22日
- In a Line
- Java 之Jtattoo皮肤应用
- 接口的一些特性,字符类型的区别
- xml和html混合和php应用程序使用xml
- JDBC操作timestamp和datetime时候应该注意的问题
- 关于项目研发重要接口需要注意的问题
- UNIX网络编程源码的使用
- 大二了,自己长大了
- hdu 3065(AC自动机)