题目:

  You've been invited to a party. The host wants to divide the guests into 2 teams for party games, with exactly the same number of guests on each team. She wants to be able to tell which guest is on which team as she greets them when they arrive. She'd like to do so as easily as possible, without having to take the time to look up each guest's name on a list.

  Being a good computer scientist, you have an idea: give her a single string, and all she has to do is compare the guest's name alphabetically to that string. To make this even easier, you would like the string to be as short as possible.

Given the unique names of n party guests (n is even), find the shortest possible string S such that exactly half the names are less than or equal to S, and exactly half are greater than S. If there are multiple strings of the same shortest possible length, choose the alphabetically smallest string from among them.

Input

There may be multiple test cases in the input.

Each test case will begin with an even integer n (2n1, 000) on its own line.

On the next n lines will be names, one per line. Each name will be a single word consisting only of capital letters and will be no longer than 30 letters.

The input will end with a `0' on its own line.

Output

For each case, print a single line containing the shortest possible string (with ties broken in favor of the alphabetically smallest) that your host could use to separate her guests. The strings should be printed in all capital letters.

Sample Input

4
FRED
SAM
JOE
MARGARET
2
FRED
FREDDIE
2
JOSEPHINE
JERRY
2
LARHONDA
LARSEN
0

Sample Output

K
FRED
JF
LARI   题意是给你一些字符串,按照字典序排好以后用一个字符串c将它们平均分开为两半,这个c要大于等于一边的所有字符串,小于另一边的所有字符串,同时要求c是最短的。
  排位赛没有做出来,后来看到盛爷的代码以后发现原来可以暴力枚举过。
  做法是先对这些字符串排序,去中间的两个串,然后按照长度从短到长枚举c,对于每一个位置都从a到前面那个字符串的当前位的字母,然后判断当前的c是否大于等于前面的串小于后面的串,如果是,就输出,否则继续枚举下一位。 代码:
 #include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#define MAX 1000
using namespace std; string s[MAX];
string c; void check(int n)
{
int j;
c="";
j=;
while()
{
c+='A';
while(c[j]<='Z')
if(s[n]>c) c[j]++;
else break;
if(c[j]<='Z' && s[n]<=c && c<s[n+]) return ;
if(s[n][j]!=c[j]) c[j]--;
j++;
}
} int main()
{
int n,i;
while(cin>>n,n)
{
c.clear();
for(i=;i<n;i++)
{
s[i].clear();
cin>>s[i];
}
sort(s,s+n);
n=n/-;
check(n);
cout<<c<<endl;
}
return ;
}

6196

												

最新文章

  1. 第六课——UIDynamicAnimator
  2. Android(Java):jni源代码
  3. 百度图片爬虫-python版
  4. c++将引用作为函数的参数---6
  5. poj1733 带权并查集
  6. Oracle SQL 劈开字符串
  7. 编译时IOS Device 无法选择的情况
  8. thinkphp 使用过程中遇到的一个小函数
  9. $_FILES系统函数
  10. Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)的解决方法
  11. Linux sed command
  12. PHP大法
  13. 最大流 USTC1280
  14. Holer实现外网访问ARM嵌入式Linux系统
  15. 关于 Kubernetes 中的 Volume 与 GlusterFS 分布式存储
  16. Rancher2.0中邮件通知的设置
  17. easyui 改变单元格背景颜色
  18. 常用类及 LeetCode 每日一题
  19. 通过 onclick = &quot;test()&quot;事件定义的事件 , 如何触发.
  20. 初始if..else 条件语句

热门文章

  1. NYOJ15括号匹配
  2. ningbooj--1655--木块拼接(贪心)
  3. 【NOI1999、LOJ#10019】生日蛋糕(搜索、最优化剪枝、可行性剪枝)
  4. jQuery 对象转成 DOM 对象
  5. Elasticsearch之curl删除索引库
  6. Oracle 数据导入导出(imp/exp)
  7. SQLServer 在存储过程里使用事务控制的简单小例子
  8. Windows phone开发 页面布局之屏幕方向
  9. 关于17个Cr的430采购的注意事项 430F
  10. Unity引擎GUI之Text