对称排序

时间限制: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)
样例输入
  1. 7
  2. Bo
  3. Pat
  4. Jean
  5. Kevin
  6. Claude
  7. William
  8. Marybeth
  9. 6
  10. Jim
  11. Ben
  12. Zoe
  13. Joey
  14. Frederick
  15. Annabelle
  16. 5
  17. John
  18. Bill
  19. Fran
  20. Stan
  21. Cece
  22. 0
样例输出
  1. SET 1
  2. Bo
  3. Jean
  4. Claude
  5. Marybeth
  6. William
  7. Kevin
  8. Pat
  9. SET 2
  10. Jim
  11. Zoe
  12. Frederick
  13. Annabelle
  14. Joey
  15. Ben
  16. SET 3
  17. John
  18. Fran
  19. Cece
  20. Stan
  21. Bill
来源
POJ
  1. #include <stdio.h>
  2. #include <string.h>
  3. typedef struct IN
  4. {
  5. char str[];
  6. int length;
  7. }IN;
  8. IN s[];
  9. int cmp(const void *a,const void *b)
  10. {
  11. return (*(IN *)a).length - (*(IN *)b).length;
  12. }
  13. int main()
  14. {
  15. int k=,T;
  16. while(scanf("%d",&T),T)
  17. {
  18. int i,j;
  19. IN t;
  20. memset(s,,sizeof(s));
  21. for(i=;i<T;i++)
  22. {
  23. scanf("%s",s[i].str);
  24. s[i].length=strlen(s[i].str);
  25. }
  26. //qsort(s,T,sizeof(s[0]),cmp);
  27. for(i=;i<T-;i++)
  28. {
  29. for(j=;j<T-i-;j++)
  30. if(s[j].length>s[j+].length)
  31. {
  32. t=s[j];
  33. s[j]=s[j+];
  34. s[j+]=t;
  35. }
  36. }
  37. printf("SET %d\n",k++);
  38. for(i=;i<T;i+=)
  39. printf("%s\n",s[i].str);
  40. if(T&)
  41. {
  42. for(i=T-;i>=;i-=)
  43. printf("%s\n",s[i].str);
  44. }
  45. else
  46. {
  47. for(i=T-;i>=;i-=)
  48. printf("%s\n",s[i].str);
  49. }
  50. }
  51. return ;
  52. }
  53. //快排貌似不行,用冒泡排序

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. PCB genesis连孔加除毛刺孔(槽孔与槽孔)实现方法(三)

    一.为什么 连孔加除毛刺孔 原因是 PCB板材中含有玻璃纤维, 毛刺产生位置在于2个孔相交位置,由于此处钻刀受力不均导致纤维切削不断形成毛刺 ,为了解决这个问题:在钻完2个连孔后,在相交处再钻一个孔, ...

  2. Balanced Lineup(线段树)

    http://poj.org/problem?id=3264 题意:n个数,q个询问,输出[l,r]中最大值与最小值的差. #include <stdio.h> #include < ...

  3. <assert.h>

    Diagnostics 定义宏: void assert (scalar-expression); 若expression为0,则打印出错信息(类似Assertion failed: expressi ...

  4. Leetcode0457--Circular Array Loop

    [转载请注明]https://www.cnblogs.com/igoslly/p/9339478.html class Solution { public: bool circularArrayLoo ...

  5. 黑马程序员 关于c# windows窗体关闭时线程未能完全退出问题(专题一)

    <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IO开发S</a> ...

  6. JS——arguments

    1.只在函数中使用 2.返回的是实参的数组 <script> getNum(1, 2);//(2) [1, 2, callee: ƒ, Symbol(Symbol.iterator): ƒ ...

  7. url中含有中文路径时访问出现404问题

    /** * URL中文字符编码转换 * @param url 含中文字符的URL * @return */ public static String getChineseURICode(String ...

  8. Python开发工具搭建-Pycharm

    PyCharm2017. 3.X专业版 安装使用. 注册码激活 本文以 Windows系统 为例: 1.开发工具获取及下载 Anaconda(Python 的集成工具 ) 下载地址: https:// ...

  9. 12--c完数/最大公约数/最小公倍数/素数/回文数

    完数/最大公约数/最小公倍数/素数/回文数 2015-04-08 10:33 296人阅读 评论(0) 收藏 举报  分类: C/C++(60)  哈尔滨工业大学(8)  版权声明:本文为博主原创文章 ...

  10. CDR如何使用钢笔工具进行完美抠图?【6·18特惠倒计时!】

    不要以为抠图只能在图像处理软件中实现,矢量图形绘制软件CorelDRAW一样可以,而且方法很多,文章介绍使用CDR钢笔工具抠图的方法. 提示说明: 首先说明一下,CDR中的钢笔工具和其他平面设计软件中 ...