| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:第一个hash,而且用了两次。。。。。想看的可以看一下In Reply To:第一个hash,而且用了两次。。。。。想看的可以看一下 Posted by:luishen at 2010-08-01 17:38:46 > 一开始直接用ascii码对应。结果就怀具了。
> 应该是加和超过范围了。。
> 代码写得脑残了。。大家可能看着费劲。。让人看不懂的代码不是好代码。。用同样方法做过的童鞋应该容易看明白些。。仅供娱乐。。
> #include <iostream>
> using namespace std;
> int hash[20000000]={0};
> char str[17000000];
> int ascii_table[255]={0};//为字母赋值
> int map [255]={0};//记录某个字母是否出现
> int main ()
> {
>
> int N; scanf("%d",&N);
> int Nc; scanf("%d",&Nc);
> scanf("%s",&str);
> int j;
> int k;
> int temp;
> int ans=0;
> int ascii=0;
> for(j=0; str[j+N-1]!='\0'; j++)
> {
> temp=0;
> for(k=0; k<N; k++)
> { if (!map[(int)str[j+k]])
> {
> map[(int)str[j+k]]=1;
> ascii_table[(int)str[j+k]]=ascii++;
> }
> temp=temp*Nc+ascii_table[(int)str[j+k]];
> }
> if (!hash[temp])
> {
> hash[temp]++;
> ans++;
> }
> }
> printf("%d\n",ans);
> return 0;
> }
map 可以不用的吧?
呵呵
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator