#include <stdio.h>
#include <string.h>
#define N 10010
#define M 10007
struct hashtabel
{
char str[200] ;
int num;
}a[N], b[N];
int hash(char *s)
{
int h = 0, a = 127;
for (; *s ; s++)
h = (a*h + *s) % M;
return h;
}
int getnum(char *s)
{
int x;
x = hash(s);
while (strcmp(a[x].str, "") && strcmp(a[x].str, s)) // 该位置有值且值不匹配串
{
x = (x+1) % M;
if (!(strcmp(a[x].str, "")))
// 找一个没有值的位置
{
strcpy(a[x].str, s);
return x;
}
}
return x;
}
int main(void)
{
char t[200];
int i, j, n, total;
for (i = 0; i < N; i++)
{
strcpy(a[i].str, "");
a[i].num = 0;
}
scanf("%d\n", &n);
for (i = 0, j = 0;
i < n; i++)
{
gets(t);
total = getnum(t);
if (a[total].num == 0)
{
strcpy(b[j].str, t);
b[j].num = total;
j++;
}
a[total].num++;
}
for (i = 0; i < j; i++)
printf("%s %d\n", b[i].str, a[b[i].num].num);
return 0;
}