283-对称排序

内存限制:64MB
时间限制:1000ms
特判: No

通过数:2
提交数:4
难度: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

C/C++  AC:

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <climits>
#define PI 3.1415926 using namespace std;
const int MY_MAX = ;
int N; bool cmp(string a, string b)
{
return a.size() < b.size();
} int main()
{
int t = ;
while (scanf("%d", &N), N)
{
string my_str[];
int flag[] = {};
for (int i = ; i < N; ++ i)
{
cin >>my_str[i];
}
sort(my_str, my_str + N, cmp); // 题目的意思,先根据长度排序 printf("SET %d\n", t ++);
for (int i = ; i < N; i += )
{
cout <<my_str[i] <<endl;
flag[i] = ;
}
for (int i = N - ; i > ; -- i)
{
if (!flag[i])
cout <<my_str[i] <<endl;
}
}
}

help

nyoj 283-对称排序 (sort)的更多相关文章

  1. Lucene 排序 Sort与SortField

    在sql语句中,有升序和降序排列.在Lucene中,同样也有. Sort里的属性 SortField里的属性 含义 Sort.INDEXORDER SortField.FIELD_DOC 按照索引的顺 ...

  2. 转:详细解说 STL 排序(Sort)

    详细解说 STL 排序(Sort) 详细解说 STL 排序(Sort) 作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1. ...

  3. NYOJ一种排序

    //最重要的收获就是懂得了,还可以调用库函数直接对结构体进行排序sort(const void *,const void *,cmp) /* bool cmp(rect c,rect d) { if( ...

  4. 设计模式 - 模板方法模式(template method pattern) 排序(sort) 具体解释

    模板方法模式(template method pattern) 排序(sort) 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考模板方法模式(tem ...

  5. [js] - 关于js的排序sort

    js的排序sort并不能一次排序好 function solution(nums){ return nums.sort(sortNumber); } function sortNumber(a, b) ...

  6. 给乱序的链表排序 · Sort List, 链表重排reorder list LoLn...

    链表排序 · Sort List [抄题]: [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: quick ...

  7. 详细解说 STL 排序(Sort)(转)

    作者Winter 详细解说 STL 排序(Sort) 0 前言: STL,为什么你必须掌握 1 STL提供的Sort 算法 1.1 所有sort算法介绍 1.2 sort 中的比较函数 1.3 sor ...

  8. nyoj_283_对称排序_201312051155

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

  9. Excel VBA解读(54):排序——Sort方法

    Excel VBA解读(54):排序——Sort方法 看看下面的Excel界面截图,“排序”和“筛选”往往在一起,这大概是很多数据需要先排序后筛选吧  首先以“性别”作为排序字段,升序排列,并且第一行 ...

随机推荐

  1. 在Hadoop上用Python实现WordCount

    一.简单说明 本例中我们用Python写一个简单的运行在Hadoop上的MapReduce程序,即WordCount(读取文本文件并统计单词的词频).这里我们将要输入的单词文本input.txt和Py ...

  2. Zeebe服务学习5-多实例特性实践

    一.背景 在0.21版本之前,Zeebe不支持多实例元素,在2019年10月9号发布的0.21版本中,加入这一特性, 主要是体现在Zeebe Modeler 0.7.0以及之后的版本中. 二.特性介绍 ...

  3. go-select

    select语句属于条件分支流程控制方法,不过它只能用于通道. select语句中的case关键字只能后跟用于通道的发送操作的表达式以及接收操作的表达式或语句. ch1 := make(chan ) ...

  4. Codeforces Round #426 The Meaningless Game

    题目网址:http://codeforces.com/contest/834/problem/C 题目: C. The Meaningless Game Slastyona and her loyal ...

  5. Centos7.4环境下搭建Python开发环境(虚拟机安装+python安装+pycharm安装)

    目录 一.安装 Centos7.4虚拟机 二.安装 python3.6.7 三.安装 pycharm 一般情况下,大家都是在 Windows平台下进行 Python开发,软件安装和环境搭建都非常&qu ...

  6. SpringBoot学习(三)探究Springboot自动装配

    目录 什么是自动装配 何时自动装配 原理分析 注:以下展示的代码springboot的版本为2.0.3版.因源码过长,大家选择展开代码 ㄟ( ▔, ▔ )ㄏ 什么是自动装配 自动装配还是利用了Spri ...

  7. python-从文件中读取数据

    一.读取整个文件 learnFile.py 绝对路径 # coding=UTF-8 import sys reload(sys) with open(r'C:\Users\zhujiachun\Des ...

  8. Kafka常用操作备忘

    启动nohup ./bin/zookeeper-server-start.sh config/zookeeper.properties &nohup ./bin/kafka-server-st ...

  9. IIS服务器文件跨域问题(几乎可以解决大多数跨域问题)

    Windows server 服务器 1:在管理工具中选择,找到IIS 2:打开IIS管理,找到网站 3:找到HTTP响应头标 4:打开HTTP响应头标 5:添加 添加:Access-Control- ...

  10. Java中Object类hashCode的底层实现

    Java中Object类hashCode的底层实现 openjdk\jdk\src\share\native\java\lang\Object.c 42 static JNINativeMethod ...