Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.
 
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.
 
Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
 
Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0
 
Sample Output
red
pink
 
Author
WU, Jiazhi
 
Source
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath> using namespace std; struct node
{
node* next[];
bool end;
int num;
node()
{
for(int i = ;i<;i++)
next[i] = NULL;
end = ;
num = ;
}
};
node* root;
char s[],ma[];
int mx;
int insert()
{
int l =strlen(s);
node* k = root;
int i,j;
for(i = ;i<l-;i++)
{
int id = s[i]-'a';
if(k->next[id] == NULL)
{
node* t = new node();
k->next[id] = t;
k = k->next[id];
}
else
{
k = k->next[id];
}
}
int id = s[i]-'a';
if(k->next[id] == NULL)
{
node* t = new node();
t->end = ,t->num = ;
k->next[id] = t;
k = k->next[id];
}
else
{
k = k->next[id];
k->num++;
}
return k->num;
} int main()
{
int n,i,j,k;
while(cin>>n,n)
{
root = new node();
mx = ;
for(i = ;i<n;i++)
{
cin>>s;
int t = insert();
if(mx<t)
{
mx = t;
int l = strlen(s);
for(j = ;j<=l;j++)
ma[j] = s[j];
}
}
cout<<ma<<endl;
}
return ; }

最新文章

  1. SignalR入门之小试身手
  2. 为什么使用&lt;!DOCTYPE HTML&gt;
  3. js的作用域
  4. 用java实现冒泡排序法
  5. mysql级联删除更新
  6. 浅谈JS执行环境及作用域
  7. Python解释器运行成功,命令运行显示无此属性解决办法
  8. js 高阶函数 map reduce
  9. Encapsulation.
  10. JMS详细的工作原理【转】
  11. 芝麻HTTP:JavaScript加密逻辑分析与Python模拟执行实现数据爬取
  12. android9.0系统适配遇到的问题
  13. ubuntu升级显卡驱动
  14. AJAX的来龙去脉(由来)-如何被封装出来的--ajax发送异步请求(四步操作)
  15. 窗口,父窗口parentwindow,所有者窗口ownerwindow
  16. JQuery+Ajax实现唯一性验证、正则
  17. java第一天!
  18. java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
  19. C# json字符串格式
  20. CRM - 销售与客户

热门文章

  1. apache 三种工作模式的讲解
  2. Android studio教程:[1] 创建app项目
  3. win7使用右键导致死机、假死、explorer无法响应的解决方法
  4. Ubuntu Server 安装部署 Cacti 服务器监控
  5. 京东UED招聘web前端开发工程师(中/高级)
  6. python运维开发(十)----IO多路复用线程基本使用
  7. Matlab 仿真实现TI Instaspin 的Foc 逆Clarke变换和SVPWM
  8. &#39;adb&#39; 不是内部或外部命令,也不是可运行的程序
  9. C语言的本质(22)——C标准库之字符串操作
  10. linux之SQL语句简明教程---WHERE