hdu 1800 哈希水题

题意

大概就是求一些重复出现的字符串中最大的次数,用map可以水过,但是时间比较慢
此题也可以用字符串哈希

代码:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 3000+100;
map<int,int> mp;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        mp.clear();
        int MAX = 0;
        for(int i=0;i<n;i++)
        {
            int tmp;
            scanf("%d",&tmp);
            mp[tmp]++;
            MAX = max(MAX,mp[tmp]);
        }
        cout<<MAX<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/q451792269/article/details/79587439