【2892】A SDUTOJ

A

Time Limit: 60ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

给出n(1<= n && n <= 2*10^6)个字符串,每个字符串只包含小写英文字母,且最多有五个。问这n个字符串中出现次数最多的有多少个。

输入

单组输入。第一行输入一个数字n,接下来n行,每行包含一个字符串。

输出

输出一个数字代表答案。

示例输入

5
aba
abb
w
aba
z

示例输出

2
 
 
字典树问题(模板型题目)
 
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node
{
    int flag;
    struct node *next[26];
}*head;
char str[1000100];
int ma=0;
struct node *creat()
{
    struct node *p;
    p=(struct node *)malloc(sizeof(struct node));
    int i;
    for(i=0;i<26;i++)
    {
        p->next[i]=NULL;
    }
    p->flag=0;
    return p;
};
void inser()
{
    int len,i,j;
    struct node *p,*q;
    len=strlen(str);
    p=(struct node *)malloc(sizeof(struct node));
    p=head;
    for(i=0; i<len; i++)
    {
        int t=str[i]-'a';
        if(p->next[t]==NULL)
        {
            p->next[t]=creat();
        }
        p=p->next[t];
    }
    p->flag++;
    if(ma<p->flag)
        ma=p->flag;
};
int main()
{
    int n,i;
    head=(struct node *)malloc(sizeof(struct node));
    for(i=0; i<26; i++)
        head->next[i]=NULL;
    head->flag=0;
    scanf("%d",&n);
    getchar();
    while(n--)
    {
        scanf("%s",str);
        inser();
    }
    printf("%d\n",ma);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值