hdu 1004(hash)
//hash
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int M = 1361;
struct node {//节点
char str[16];
int count;
node *next;
}s[M];
int maxs;
char ans[16];
void init() {//初始化
for (int i=0; i<M; ++i) {
s[i].next = NULL;
s[i].count = 0;
}
}
unsigned int BKDRHash(char str[]) {//hash
unsigned int seed = 131;
unsigned int hash = 0;
while (*str) hash = hash * seed + (*str++);
return (hash & 0x7FFFFFFF);
}
void solve(char ch[]) {
int k = BKDRHash(ch) % M;
node *p, *q;
p = s[k].next;
while (p != NULL) {
if (strcmp(p->str, ch) == 0) {
++p->count;
if (maxs < p->count) {
maxs = p->count;
strcpy(ans, p->str);
}
return ;
}
p = p->next;
}
q = new node;
q->count = 1;
q->next = NULL;
strcpy(q->str, ch);
q->next = s[k].next;
s[k].next = q;
if (maxs < q->count) {
maxs = q->count;
strcpy(ans, q->str);
}
return ;
}
void del(node *p) {//释放内存
if (p == NULL) return ;
del(p->next);
delete p;
}
int main() {
int n;
char ch[16];
while (scanf("%d", &n), n) {
init();
maxs = -1;
for (int i=0; i<n; ++i) {
scanf ("%s", ch);
solve(ch);
}
for (i=0; i<n; ++i) {
if (s[i].next != NULL) del(s[i].next);
}
printf ("%s\n", ans);
}
return 0;
}