hash(key)=hash+i*i
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
long int boxes[10]={0};//用数组做//
long int sum=0;//long int,电话号码太长了//
char initial[100];
int i=0;
char ch;
int hash=0;
int amount=1;
int length=0;
int collision=0;
scanf("%s",initial);
length=strlen(initial);
for(int j=0;j<length;j++)
{
if(initial[j]==',')
{
amount++;//查询有多少个数据//
}
}
for(int k=0;k<amount;k++)
{
ch=initial[i];
sum=0;
if(ch==',')
{
i++;
}
ch=initial[i];
while(ch!=','&&ch!='\0')
{
sum=sum+atoi(&ch);
sum=sum*10;
i++;
ch=initial[i];
}
sum=sum/10;//sum是电话号码的整数型
collision=0;
hash=sum%10;
int HASH;
HASH=hash;
while(boxes[HASH]!=0)//冲突
{
collision++;
HASH=(hash+collision*collision)%10;
}
boxes[HASH]=sum;
}
for(i=0;i<10;i++)
{
printf("%ld",boxes[i]);
if(i!=9)
{
printf(",");
}
}
return 0;
}