短文评估[Hash]

网友投稿 593 2022-09-09

短文评估[Hash]

短文评估[Hash]

Hash表

Hash最好用map+unsigned long long 写,不用取模,自动溢出

#define ULL unsigned long long map Map;while(pd(ch=getchar())){ if(ch>='A'&&ch<='Z') ch=ch+'a'-'A'; sum=sum*31+ch;}Map[sum]++;for(map::iterator i=Map.begin();i!=Map.end();i++) int cur=i->second;

代码

#include#define ULL unsigned long long using namespace std;map Map;bool pd(char ch){ if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) return true; return false;}bool read(){ char ch; ULL sum=0; while(!pd(ch=getchar())) if(ch==EOF) return 0; if(ch>='A'&&ch<='Z') ch=ch+'a'-'A'; sum=sum*31+ch; while(pd(ch=getchar())){ if(ch>='A'&&ch<='Z') ch=ch+'a'-'A'; sum=sum*31+ch; } Map[sum]++; return 1;}int main(){ int n,ans=0,cnt=0; while(read()) cnt++; for(map::iterator i=Map.begin();i!=Map.end();i++){ int cur=i->second; ans+=cur*cur*cur*cur; } cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:数位DP进阶
下一篇:python format函数/print 函数详细讲解(4)(python培训)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~