nyoj_283_对称排序_201312051155
对称排序
- 描述
-
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的更多相关文章
- 【南阳OJ分类之语言入门】80题题目+AC代码汇总
小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...
- go排序
补注: 近来又看 go 的排序, 发现以前对 go 的排序理解的有点浅了. go 的排序思路和 c 和 c++ 有些差别. c 默认是对数组进行排序, c++ 是对一个序列进行排序, go 则更宽泛一 ...
- 操作系统学习笔记 对称多处理(SMP)
SMP:一种通过复用处理器提高程序执行并行性的方式. 根据SMP,计算机系统可以分为以下四类: 单指令单数据流(SISD):一个单处理器执行一个单指令流,对保存在一个存储器中的数据进程进行操作. 单指 ...
- C++排列对称串
题目内容:字符串有些是对称的,有些是不对称的,请将那些对称的字符串按从小到大的顺序输出.字符串先以长度论大小,如果长度相同,再以ASCII码值为排序标准. 输入描述:输入数据中含有一些字符串(1< ...
- 八大排序方法汇总(选择排序,插入排序-简单插入排序、shell排序,交换排序-冒泡排序、快速排序、堆排序,归并排序,计数排序)
2013-08-22 14:55:33 八大排序方法汇总(选择排序-简单选择排序.堆排序,插入排序-简单插入排序.shell排序,交换排序-冒泡排序.快速排序,归并排序,计数排序). 插入排序还可以和 ...
- 关于javascript 数组的正态分布排序的一道面试题
最近几天顶着上海40°的凉爽天气找工作,心里是开心的不要不要的,每次面试都是要坐那里出半天汗才能回过神来,感觉到了这个世界对我深深的爱意,言归正传,面试过程中碰到了几次笔试,其中有这么一道题,由于实际 ...
- 《算法导论》 — Chapter 7 高速排序
序 高速排序(QuickSort)也是一种排序算法,对包括n个数组的输入数组.最坏情况执行时间为O(n^2). 尽管这个最坏情况执行时间比較差.可是高速排序一般是用于排序的最佳有用选择.这是由于其平均 ...
- “盛大游戏杯”第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 描述 在一个矩形的灰度图像上,每个 ...
- poj 3683 2-sat建图+拓扑排序输出结果
发现建图的方法各有不同,前面一题连边和这一题连边建图的点就不同,感觉这题的建图方案更好. 题意:给出每个婚礼的2个主持时间,每个婚礼的可能能会冲突,输出方案. 思路:n个婚礼,2*n个点,每组点是对称 ...
随机推荐
- 【RAID在数据库存储上的应用 】
随着单块磁盘在数据安全.性能.容量上呈现出的局限,磁盘阵列(Redundant Arrays of Inexpensive/Independent Disks,RAID)出现了,RAID把多块独立的磁 ...
- weak看iOS面试
2013年 面试官:代理用weak还是strong? 我 :weak . 面试官:明天来上班吧 2014年 面试官:代理为什么用weak不用strong? 我 : 用strong会造成循环引用. 面试 ...
- Redis基本属性的使用-详细
Redis 数据结构简介 Redis 可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为String(字符串).List(列表).Set(集合).Hash(散列)和 Zset(有序集 ...
- hbuilder中的 http://www.w3.org/TR/html4/strict.dtd
<!-- This is HTML 4.01 Strict DTD, which excludes the presentation attributes and elements that W ...
- Elasticsearch之CURL命令的mget查询
我这里, 再,创建一个zhouls2的索引库. [hadoop@master elasticsearch-]$ curl -XPUT 'http://master:9200/zhouls2/' {]$ ...
- scala的Class
先看类的定义: package com.test.scala.test import scala.beans.BeanProperty /** * scala 的类 */ //定义一个scala的类 ...
- jQuery封装的选项卡方法
********************************************************2018/3/15更新********************************* ...
- Beta Edition [ Group 1 ]
DeltaFish Beta Edition 一.七月开发过程 小组会议 DeltaFish 校园物资共享平台 第八次小组会议 GITHUB https://github.com/DeltaFishS ...
- JS中for循环多个变量的判断原理
看完下面两个例子的比较就明白了,其实就是逗号表达式,总是依据最后一个表达式的值. for(i=0, j=0; i<10, j<6; i++, j++){ k = i + j; consol ...
- 【技术累积】【点】【java】【28】Map遍历
Map遍历 map的遍历一般有几种吧 遍历entrySet for(Map.Entry<String,String> entry : map.entrySet()){ } Iterator ...