对称排序

时间限制: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
 1 #include <stdio.h>
 2 #include <string.h>
 3 typedef struct IN
 4 {
 5     char str[30];
 6     int length;
 7 }IN;
 8 IN s[20];
 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=1,T;
16     while(scanf("%d",&T),T)
17     {
18         int i,j;
19         IN t;
20         memset(s,0,sizeof(s));
21         for(i=0;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=0;i<T-1;i++)
28         {
29             for(j=0;j<T-i-1;j++)
30             if(s[j].length>s[j+1].length)
31             {
32                 t=s[j];
33                 s[j]=s[j+1];
34                 s[j+1]=t;
35             }
36         }
37         printf("SET %d\n",k++);
38         for(i=0;i<T;i+=2)
39         printf("%s\n",s[i].str);
40         if(T&1)
41         {
42             for(i=T-2;i>=0;i-=2)
43             printf("%s\n",s[i].str);
44         }
45         else
46         {
47             for(i=T-1;i>=0;i-=2)
48             printf("%s\n",s[i].str);
49         }
50     }
51     return 0;
52 }
53 //快排貌似不行,用冒泡排序 

转载于:https://www.cnblogs.com/xl1027515989/p/3459385.html

nyoj_283_对称排序_201312051155相关推荐

  1. 7-47 对称排序 (25 分)

    7-47 对称排序 (25 分) 你供职于由一群丑星作为台柱子的信天翁马戏团.你刚完成了一个程序编写,它按明星们姓名字符串的长度非降序(即当前姓名的长度至少与前一个姓名长度一样)顺序输出他们的名单.然 ...

  2. nyoj 题目283 对称排序

     http://acm.nyist.net/JudgeOnline/problem.php?pid=283 对称排序 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 ...

  3. 对称排序 nyoj 283

    对称排序 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 In your job at Albatross Circus Management (yes, it's ru ...

  4. NYOJ283对称排序

    对称排序 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 In your job at Albatross Circus Management (yes, it's ru ...

  5. 星期四定律。散分!_星期四

    星期四定律.散分! Zeldman writes about the last few days. My list of people I'm keeping in my prayers grows ...

  6. 【NYOJ 分类——语言入门】——汇总(六)

    题目266 题目信息 运行结果 本题排行 讨论区 字符串逆序输出 时间限制:3000 ms  |  内存限制:65535 KB 难度:0 描述 给定一行字符,逆序输出此行(空格.数字不输出) 输入 第 ...

  7. LeetCode实战:排序链表

    背景 为什么你要加入一个技术团队? 如何加入 LSGO 软件技术团队? 我是如何组织"算法刻意练习活动"的? 为什么要求团队的学生们写技术Blog 题目英文 Sort a link ...

  8. LeetCode实战:搜索旋转排序数组

    题目英文 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ...

  9. LeetCode实战:删除排序数组中的重复项

    题目英文 Given a sorted array nums, remove the duplicates in-place such that each element appear only on ...

最新文章

  1. c语言输出三个比值为,请问如何用C语言表示数的比值
  2. 2021年春季学期-信号与系统-第六次作业参考答案-第十小题
  3. C#去掉字符串中的汉字
  4. 手把手配置Linux透明防火墙
  5. 使用代码删除IBASE object component
  6. Java学习笔记---接口
  7. MySQL(9)主从复制和读写分离
  8. win10如何关闭Windows Defender安全保护程序
  9. Flutter AnimatedWidget 实现动画的自动刷新
  10. C++_二维数组_定义方式_数组名称的作用_案例考试成绩统计---C++语言工作笔记021
  11. 【linux】sed -e 's/-//g'
  12. 『转载』看c#打印的各种技术
  13. CSocket 和CAsyncSocket类介绍
  14. XposedBridgeApi-54
  15. TOGAF认证自学宝典V2.0
  16. PHP100视频教程(2012-2013版)下载地址及密码
  17. 华三交换机配置access命令_H3C交换机配置命令大全讲解
  18. 扩展卡尔曼滤波(EKF)
  19. 百度网盘解析工具 利用IDM等工具提速下载
  20. The operator ‘SUBTRACT‘ is not supported between objects of type ‘null‘ and ‘java.lang.Integer‘

热门文章

  1. FPGA的三个时代,最初三十年的回顾(附原英文资料)
  2. MSVC C/C++编译器选项 cl命令参数
  3. springboot整合dubbo设置全局唯一ID进行日志追踪
  4. 【STM32H7的DSP教程】第32章 STM32H7的实数FFT的逆变换(支持单精度和双精度)
  5. php gb28181,EasyGBS国标流媒体服务器GB28181国标方案安装使用文档
  6. 计算机实验楼应用需求分析,校园网络信息化需求分析报告
  7. Unity全局光照/Bake GI/Precomputed Real-time GI/Lightmap/Light Probe
  8. 初学者如何入门安全测试?
  9. linux4==阿里云ECS centos8部署redis6.2.6伪集群
  10. 两位前阿里 P10 的成长经历的启发