标签:printf blog c++ span n+1 seed har while i+1
题目大意、算法、思路:略。模板题,hash不多解释。
C++ Code:
#include<cstdio> #include<algorithm> using std::sort; #define seed 233 int n; char s[1555]; unsigned int a[10005]; inline unsigned int hash(char* s){ int h=0; while(*s++)h=h*seed+(*s); return h%0x7fffffff; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%s",s); a[i]=hash(s); } sort(a+1,a+n+1); a[n+1]=-1; int ans=0; for(int i=1;i<=n;i++) if(a[i]!=a[i+1])ans++; printf("%d\n",ans); return 0; }
标签:printf blog c++ span n+1 seed har while i+1
原文地址:http://www.cnblogs.com/Mrsrz/p/6986046.html