对称排序

时间限制: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. Java - HashTable、HashMap和LinkedHashMap的区别

    一般情况下,我们用的最多的是HashMap,在Map 中插入.删除和定位元素,HashMap 是最好的选择.但如果您要按自然顺序或自定义顺序遍历键,那么TreeMap会更好.如果需要输出的顺序和输入的 ...

  2. Linux运维人员-服务器组成硬件基础

    第1章 1.1关于运维人员 1.1.1 运维的职责 数据不能丢 网站7*24小时运行 保证用户体验(用户体验要好) 1.1.2 运维原则 简单.易用.高效  === 简单.粗暴 1.2 服务器 1.2 ...

  3. php获得文件的属性

    PHP获取文件属性可以用到多种函数,来实现我们对文件各种不同信息的获取需求.在这里我们就简单的介绍了这些获取方式的实现方法. 详细解读PHP获取远程图片技巧 详细介绍PHP读取目录函数 如何运用相关函 ...

  4. oracle 误删数据

    insert into hr.job_history select * from hr.job_history as of timestamp to_timestamp('2007-07-23 10: ...

  5. tp 3.2 组合查询, 字符串模式查询

    $User = M("User"); // 实例化User对象 $map['id'] = array('neq',1); $map['name'] = 'ok'; $map['_s ...

  6. JSP执行原理图

  7. 高斯消元_HihoCoderOffer6_03

    题目3 : 图像算子 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在图像处理的技术中,经常会用到算子与图像进行卷积运算,从而达到平滑图像或是查找边界的效果. 假设原图 ...

  8. 深入理解async和await的作用及各种适用场景和用法

    https://www.cnblogs.com/yaopengfei/archive/2018/07/02/9249390.html https://www.cnblogs.com/xianyudot ...

  9. python框架之Flask基础篇(三)-------- 模版的操作

    1.flask特有的变量和函数: 变量:g.session.request.config 函数:url_for().get_flashed_messages()这个函数注意了啊,记住这是个函数,别忘了 ...

  10. Android popupwindow和dialog监听返回键

    使用情况: 在activity中,出现了popupwindow和dialog,这个时候,如果点击返回键,它们消失了,但是一些操作还在继续.如:1.进行耗时操作,出现dialog提醒用户等待,这时,按下 ...