COGS 2769. mk去撸串

【题目描述】

今天 mk 去撸串 ,恰逢店里活动 ,如果吃一种串串超过记录, 可以

赠送 328, 所以 mk 想知道他吃的串串中吃的最多的种类是什么.

【输入格式】

第一行一个整数 1<=n<=50000;

然后有 n 行长度<=100 的全部由小写字母组成的字符串;每个代表一种串串

【输出格式】

同种字符串最多出现次数

【样例输入】

4

abcd

abcd

abcd

ac

【样例输出】

3

【提示】

对于 40%数据 1<=n<=3000;

对于 100%数据 1<=n<=50000;

【来源】

mk

hash

Mod值取了好几次才对 唉还是我太弱了

屠龙宝刀点击就送

#include <cstring>
#include <cstdio>
#define N 50005
#define Mod 49477

int n,ans,Hash[N];
char str[105];
int main(int argc,char *argv[])
{
    freopen("string_.in","r",stdin);
    freopen("string_.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%s",str);
        int v=0;
        int len=strlen(str);
        for(int i=0;i<len;++i) v=(v*19+str[i]-'A')%Mod;
        Hash[v]++;
        if(Hash[v]>ans)
        ans=Hash[v];
    }
    printf("%d
",ans);
    return 0;
}
原文地址:https://www.cnblogs.com/ruojisun/p/7688459.html