# 对称排序

## 对称排序

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.

```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```
```
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(string a,string b)
{
return a.length()<b.length();
}
int main(){
string s[20],temp;
int i,j,n,t=0;
while(cin>>n&&n){
t++;
for(i=0;i<n;i++)cin>>s[i];
sort(s,s+n,cmp);
cout<<"SET "<<t<<endl;
for(i=0;i<n;i++)if(i%2==0)cout<<s[i]<<endl;
for(i=n-1;i>=1;i--)if(i%2!=0)cout<<s[i]<<endl;
}
return 0;
}        ```

0 条评论

• ### VF

Vasya is the beginning mathematician. He decided to make an important contributi...

• ### Binary String Matching

Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is...

• ### Flexbox 练习和总结

练习地址： http://flexboxfroggy.com/ Welcome to Flexbox Froggy, a game where you help...

• ### numpy.geomspace

版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明...

• ### From High Ceph Latency to Kernel Patch with eBPF/BCC

There are a lot of tools for debugging kernel and userspace programs in Linux. M...

• ### 3D角色设定全析百图斩

? 我们在3D角色模型与动画设定上积累厚实，在卡噗角色设定中，我们做了很多的风格尝试以及整体配饰穿搭，去达到新锐时尚的品牌目标。回看角色设定已超过100体，在...

• ### What are x509 certificates? RFC? ASN.1? DER?

So, RFC means Request For Comments and they are a bunch of text files that descr...

• ### AMD Zen-2 物理设计总结

Last year AMD introduced the Zen 2 microarchitecture, the company’s second major...

• ### U-Net - Convolutional Networks 论文翻译——中英文对照

翻译论文汇总：https://github.com/SnailTyan/deep-learning-papers-translation