Flying to the Mars HDU

Flying to the Mars

 HDU - 1800 

题意:求最多有多少个数字相等,数可能很大,30位。

本来直接map就可以,练习一下哈希,先映射成数再用的map。。。

 1 #include <cstring>
 2 #include <iostream>
 3 #include <cstdio>
 4 using namespace std;
 5 #include <map>
 6 
 7 map<int,int> mp;
 8 int ha(char *s)
 9 {
10     int hashval=0;
11     int seed=131;
12     int i=0;
13     while(s[i]=='0') i++;
14     for(;s[i];i++){
15         hashval=hashval*seed+s[i];
16     }
17     return hashval;
18 }
19 char s[33];
20 int main()
21 {
22     int n;
23     while(scanf("%d",&n)!=EOF){
24         int ans=0;
25         mp.clear();
26         for(int i=0;i<n;i++){
27             scanf("%s",s);
28             int k=ha(s);
29             mp[k]++;
30             if(mp[k]>ans)ans=mp[k];
31         }
32         printf("%d
",ans);
33     }
34 }
View Code
原文地址:https://www.cnblogs.com/yijiull/p/7388244.html