对称排序

时间限制:1000 ms  |           内存限制:65535 KB
难度:1
 
描述
In your job at Albatross Circus Management (yes, it's run by a bunch of clowns), you have just finished writing a program whose output is a list of names in nondescending order by length (so that each name is at least as long as the one preceding it). However, your boss does not like the way the output looks, and instead wants the output to appear more symmetric, with the shorter strings at the top and bottom and the longer strings in the middle. His rule is that each pair of names belongs on opposite ends of the list, and the first name in the pair is always in the top part of the list. In the first example set below, Bo and Pat are the first pair, Jean and Kevin the second pair, etc.
 
输入
The input consists of one or more sets of strings, followed by a final line containing only the value 0. Each set starts with a line containing an integer, n, which is the number of strings in the set, followed by n strings, one per line, NOT SORTED. None of the strings contain spaces. There is at least one and no more than 15 strings per set. Each string is at most 25 characters long.
输出
For each input set print "SET n" on a line, where n starts at 1, followed by the output set as shown in the sample output. If length of two strings is equal,arrange them as the original order.(HINT: StableSort recommanded)
样例输入
7
Bo
Pat
Jean
Kevin
Claude
William
Marybeth
6
Jim
Ben
Zoe
Joey
Frederick
Annabelle
5
John
Bill
Fran
Stan
Cece
0
样例输出
SET 1
Bo
Jean
Claude
Marybeth
William
Kevin
Pat
SET 2
Jim
Zoe
Frederick
Annabelle
Joey
Ben
SET 3
John
Fran
Cece
Stan
Bill
来源
POJ
 #include <stdio.h>
#include <string.h>
typedef struct IN
{
char str[];
int length;
}IN;
IN s[];
int cmp(const void *a,const void *b)
{
return (*(IN *)a).length - (*(IN *)b).length;
}
int main()
{
int k=,T;
while(scanf("%d",&T),T)
{
int i,j;
IN t;
memset(s,,sizeof(s));
for(i=;i<T;i++)
{
scanf("%s",s[i].str);
s[i].length=strlen(s[i].str);
}
//qsort(s,T,sizeof(s[0]),cmp);
for(i=;i<T-;i++)
{
for(j=;j<T-i-;j++)
if(s[j].length>s[j+].length)
{
t=s[j];
s[j]=s[j+];
s[j+]=t;
}
}
printf("SET %d\n",k++);
for(i=;i<T;i+=)
printf("%s\n",s[i].str);
if(T&)
{
for(i=T-;i>=;i-=)
printf("%s\n",s[i].str);
}
else
{
for(i=T-;i>=;i-=)
printf("%s\n",s[i].str);
}
}
return ;
}
//快排貌似不行,用冒泡排序

nyoj_283_对称排序_201312051155的更多相关文章

  1. 【南阳OJ分类之语言入门】80题题目+AC代码汇总

    小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...

  2. go排序

    补注: 近来又看 go 的排序, 发现以前对 go 的排序理解的有点浅了. go 的排序思路和 c 和 c++ 有些差别. c 默认是对数组进行排序, c++ 是对一个序列进行排序, go 则更宽泛一 ...

  3. 操作系统学习笔记 对称多处理(SMP)

    SMP:一种通过复用处理器提高程序执行并行性的方式. 根据SMP,计算机系统可以分为以下四类: 单指令单数据流(SISD):一个单处理器执行一个单指令流,对保存在一个存储器中的数据进程进行操作. 单指 ...

  4. C++排列对称串

    题目内容:字符串有些是对称的,有些是不对称的,请将那些对称的字符串按从小到大的顺序输出.字符串先以长度论大小,如果长度相同,再以ASCII码值为排序标准. 输入描述:输入数据中含有一些字符串(1< ...

  5. 八大排序方法汇总(选择排序,插入排序-简单插入排序、shell排序,交换排序-冒泡排序、快速排序、堆排序,归并排序,计数排序)

    2013-08-22 14:55:33 八大排序方法汇总(选择排序-简单选择排序.堆排序,插入排序-简单插入排序.shell排序,交换排序-冒泡排序.快速排序,归并排序,计数排序). 插入排序还可以和 ...

  6. 关于javascript 数组的正态分布排序的一道面试题

    最近几天顶着上海40°的凉爽天气找工作,心里是开心的不要不要的,每次面试都是要坐那里出半天汗才能回过神来,感觉到了这个世界对我深深的爱意,言归正传,面试过程中碰到了几次笔试,其中有这么一道题,由于实际 ...

  7. 《算法导论》 — Chapter 7 高速排序

    序 高速排序(QuickSort)也是一种排序算法,对包括n个数组的输入数组.最坏情况执行时间为O(n^2). 尽管这个最坏情况执行时间比較差.可是高速排序一般是用于排序的最佳有用选择.这是由于其平均 ...

  8. “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】

    黑白图像直方图 发布时间: 2017年7月9日 18:30   最后更新: 2017年7月10日 21:08   时间限制: 1000ms   内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...

  9. poj 3683 2-sat建图+拓扑排序输出结果

    发现建图的方法各有不同,前面一题连边和这一题连边建图的点就不同,感觉这题的建图方案更好. 题意:给出每个婚礼的2个主持时间,每个婚礼的可能能会冲突,输出方案. 思路:n个婚礼,2*n个点,每组点是对称 ...

随机推荐

  1. 04、抽取BaseActivity

    // 在使用SDK各组件之前初始化context信息,传入ApplicationContext // 注意该方法要再setContentView方法之前实现 // SDKInitializer.ini ...

  2. java动态代理实例

    import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflec ...

  3. poj1611 并查集 (路径压缩)

    http://poj.org/problem?id=1611 题目大意: 有一个学校,有N个学生,编号为0-N-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染,并且这些人如果还参加了别的社 ...

  4. css bug(ie6兼容问题)

    二.五大浏览器内核1.trident(MSHTML)(三叉戟:三叉线,三齿鱼叉) Gecko (壁虎) presto(迅速的) webkit(safari内核,Chrome内核原型,他是苹果公司自己的 ...

  5. [Swift通天遁地]四、网络和线程-(4)使用Alamofire实现网络请求

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. 数据库mysql原生代码基本操作

    创建表: CREATE TABLE `biao` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '测试表', `createtime` ...

  7. Flume NG基本架构与Flume NG核心概念

    导读 Flume NG是一个分布式.可靠.可用的系统,它能够将不同数据源的海量日志数据进行高效收集.聚合.移动,最后存储到一个中心化数据存储系统中. 由原来的Flume OG到现在的Flume NG, ...

  8. Redis 的简单运算

    Redis 的简单运算 命令 说明 备注 incr key 在原字段上加 1 只能对整数操作 incrby key increment 在原字段上加上整数 (increment) 只能对整数操作 de ...

  9. HTTP05--HTML常用知识

    一.URL地址含义 需要搞清URL和URI的差别,以及QueryString的含义. 二.GET和POST的区别 详细介绍可参考文章:http://zengrong.net/post/1802.htm ...

  10. dubbo之主机绑定

    主机绑定 查找顺序 缺省主机 IP 查找顺序: 通过 LocalHost.getLocalHost() 获取本机地址. 如果是 127.* 等 loopback 地址,则扫描各网卡,获取网卡 IP. ...