对称排序

简介:

对称排序

时间限制: 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

查看代码---运行号:252342----结果:Accepted

运行时间: 2012-10-05 16:35:20  |  运行人: huangyibiao
01. #include <iostream>
02. #include <string>
03. #include <vector>
04. using namespace std;
05.  
06. int main()
07. {
08. int t;
09. string tmp;
10. int set = 1;
11. while (cin >> t && t != 0)
12. {
13. int i = 1;
14. vector<string> vEven, vOdd, v;
15.  
16. for (i = 0; i < t; i++)
17. {
18. cin >> tmp;
19. v.push_back(tmp);
20. }
21. for (i = 0; i < t; i++)
22. {
23. for (int j = 0; j < t-i-1; j++)
24. {
25. if (v[j].size() > v[j+1].size())
26. {
27. string s = v[j];
28. v[j] = v[j+1];
29. v[j+1] = s;
30. }
31. }
32. }
33. for (i = 1; i <= t; i++)
34. {
35. if (i % 2)//奇数位置
36. vOdd.push_back(v[i-1]);
37. else
38. vEven.push_back(v[i-1]);
39. }
40. cout << "SET " << set++ << endl;
41. for (vector<string>::iterator it = vOdd.begin(); it != vOdd.end(); it++)
42. {
43. cout << *it << endl;
44. }
45. for (vector<string>::reverse_iterator it = vEven.rbegin(); it != vEven.rend(); it++)
46. {
47. cout << *it << endl;
48. }
49.  
50. }
51. return 0;
52. }

目录
相关文章
|
缓存 NoSQL 数据库
优酷投票系统设计和重构
     介绍优酷投票系统,承载了优酷暑假战役、寒假战役、双十一促销,以及平时各自营销套路活动,系统设计相对合理,实现一塌糊涂,有代码为证(参考:列举一些神奇的代码)。重构的理由:代码僵化,难以改动,新增一个字段改动多出代码代码脆弱,改动会出现意想不到的情况,改一个bug引发无数bug代码晦涩,代码难以阅读理解,多位前任改bug的代码实现套娃式的修复投票系统的设计基础名词:投票活动,投票渠道,投票
829 0
优酷投票系统设计和重构
|
存储 Kubernetes Perl
pv和pvc的区别、关系,如何设置使用的步骤
PV(Persistent Volume)和 PVC(Persistent Volume Claim)是 Kubernetes 中用于管理持久化存储的两个关键概念。 PV 是集群中的一个持久化存储资源,它是由集群管理员预先创建和配置的。PV 可以是物理存储设备、存储阵列、网络存储等。PV 有自己的生命周期,并且可以被多个 Pod 共享。 PVC 是 Pod 对 PV 的请求,它用于声明 Pod 对存储的需求。PVC 描述了 Pod 所需的存储容量、访问模式等属性。当创建 PVC 时,Kubernetes 会尝试将其与可用的 PV 进行匹配和绑定。一旦 PVC 成功绑定到 PV,Pod 就可
1612 0
|
运维 监控 安全
阿里云香港轻量应用服务器评测,1核1G 30M 24元/月,低价VPS
阿里云香港轻量应用服务器评测,1核1G 30M 24元/月,低价VPS
5689 0
|
传感器 机器人
Gazebo物理仿真环境搭建
## 仿真步骤 - 配置机器人模型 - 创建仿真环境 - 开始仿真
Gazebo物理仿真环境搭建
|
Java 数据库连接 Spring
Spring Boot 四大核心组件,你知道几个?(1)
Spring Boot 四大核心组件,你知道几个?(1)
618 0
Spring Boot 四大核心组件,你知道几个?(1)
什么是多路复用?描述不同类型的复用技术
多路复用是一种技术,其中几个消息信号被组合成一个复合信号,以便在一个公共信道上传输。这些要在公共信道上传输的信号必须保持分开,以便它们不会相互干扰,因此它们可以在接收端很容易地分离。
988 0
什么是多路复用?描述不同类型的复用技术
|
移动开发 小程序 IDE
小程序测试全攻略,还学不会你来找我(含实操代码)
小程序测试全攻略,还学不会你来找我(含实操代码)
758 0
|
人工智能 前端开发 程序员
为什么 Roblox 会给单个开发者开出 800 万年薪?
一家游戏平台公司给首席工程师支付的年薪,相当于这家公司初创阶段拿到的首轮投资的两倍之多。
507 0
为什么 Roblox 会给单个开发者开出 800 万年薪?
|
存储 jstorm 消息中间件
mPaas-MAS服务端架构介绍
移动分析服务(Mobile Analysis Service,简称 MAS)是 mPaaS 平台的一个核心基础服务组件,是一项方便您轻松地大 规模收集、可视化并理解应用程序使用数据的服务。MAS 通过统计和分析客户端流量、性能质量和用户行为等数据,用数 据实现产品、运营、推广的决策;通过对闪退的分析,快速定位闪退原因,提高程序稳定性。
1547 0
mPaas-MAS服务端架构介绍
|
存储 域名解析 编解码
如何有效节省阿里云视频点播的使用成本
背景       视频,现在已经成为人们越来越喜欢的交流和沟通方式,各种点播、直播平台、短视频APP层出不穷,吸引了大量的用户群体,而对于视频行业来说,存储和分发是需要考虑的核心部分。如何保证视频存储的可靠性和安全性,视频分发的速度以及稳定性,是每一个视频行业的用户需要考虑的问题。
7736 0
如何有效节省阿里云视频点播的使用成本