NYOJ283对称排序
对称排序
- 描述
-
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
1 2 #include <iostream> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 using namespace std; 7 string str1[26],str2[26]; 8 bool cmp(string a,string b) 9 { 10 return a.length()<b.length(); 11 } 12 int main() 13 { 14 int n,i,j,k,t=1; 15 while(cin>>n,n) 16 { 17 j=0;k=n-1; 18 for( i = 0 ; i < n ; i ++ ) 19 cin>>str1[i]; 20 sort(str1,str1+n,cmp); 21 for( i = 0 ; i < n ; i ++ ) 22 { 23 if( i & 1 == 0 ) 24 str2[j++] = str1[i]; 25 else 26 str2[k--] = str1[i]; 27 } 28 cout<<"SET "<<t++<<endl; 29 for(i=0;i<n;i++) 30 cout<<str2[i]<<endl; 31 } 32 return 0; 33 } 34
NYOJ283对称排序相关推荐
- 7-47 对称排序 (25 分)
7-47 对称排序 (25 分) 你供职于由一群丑星作为台柱子的信天翁马戏团.你刚完成了一个程序编写,它按明星们姓名字符串的长度非降序(即当前姓名的长度至少与前一个姓名长度一样)顺序输出他们的名单.然 ...
- nyoj_283_对称排序_201312051155
对称排序 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 In your job at Albatross Circus Management (yes ...
- nyoj 题目283 对称排序
http://acm.nyist.net/JudgeOnline/problem.php?pid=283 对称排序 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 ...
- 对称排序 nyoj 283
对称排序 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 In your job at Albatross Circus Management (yes, it's ru ...
- 星期四定律。散分!_星期四
星期四定律.散分! Zeldman writes about the last few days. My list of people I'm keeping in my prayers grows ...
- 【NYOJ 分类——语言入门】——汇总(六)
题目266 题目信息 运行结果 本题排行 讨论区 字符串逆序输出 时间限制:3000 ms | 内存限制:65535 KB 难度:0 描述 给定一行字符,逆序输出此行(空格.数字不输出) 输入 第 ...
- LeetCode实战:排序链表
背景 为什么你要加入一个技术团队? 如何加入 LSGO 软件技术团队? 我是如何组织"算法刻意练习活动"的? 为什么要求团队的学生们写技术Blog 题目英文 Sort a link ...
- LeetCode实战:搜索旋转排序数组
题目英文 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ...
- LeetCode实战:删除排序数组中的重复项
题目英文 Given a sorted array nums, remove the duplicates in-place such that each element appear only on ...
最新文章
- mysql 开仓函数_MySQL函数大全 及用法示例
- 库克称苹果不会学脸书发行加密货币
- python matplotlib:figure,add_subplot,subplot,subplots讲解实现
- Sharepoint学习笔记—Site Definition系列-- 1、创建Site Columns
- 77岁“核弹老人”,前后半生都令人动容!
- dict过滤 python_小猿圈解析Python开发的技巧都有哪些?
- LeetCode:10.regular-expression-matching(正则式表达)
- shell使用sshpass自动验证root密码
- java manager 如何使用_java – Android:如何使用AlarmManager
- 说好的 All in AI,没想到科技巨头们都开始偷偷的挖矿中!
- 2018-2019-2 网络对抗技术 20165115 Exp6 信息搜集与漏洞扫描
- 神策数据盛永根:微信生态——全数据采集和打通
- 终端中显示git分支名称的方法
- (栈的应用5.2.2)POJ 2106 Boolean Expressions(表达式求值)
- 大数据量(例如几十万或者几百万的量)怎么导入到excel中
- Linux磁盘分区与LVM详解
- matlab bsxfun memory,matlab – BSXFUN关于关系操作的内存效率
- mcafee杀毒软件编写规则时通配符使用方法
- 实验9_7_设计函数int getVowel(char str[],char vowel[]);
- Thirteen 外卖店优先级