| ||||||||||
| 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 | |||||||||
c语言的源代码#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//#include<iostream>
//using namespace std;
struct map
{
int size;
int phone;
};
struct hashmap
{
int size;
struct map *hash[3000];
};
void rmhyphen(char a[],char b[])
{
int i,j,k;
k=0;
i=strlen(a);
for(j=0;j<i;j++)
{
if(a[j]!='-')
{
b[k]=a[j];
k++;
}
}
b[k]=0;
}
int ctoi(char a[])
{
int i,j;
i=strlen(a);
for(j=0;j<i;j++)
{
if(a[j]=='A'||a[j]=='B'||a[j]=='C'||a[j]=='2')
a[j]='2';
else if(a[j]=='D'||a[j]=='E'||a[j]=='F'||a[j]=='3')
a[j]='3';
else if(a[j]=='G'||a[j]=='H'||a[j]=='I'||a[j]=='4')
a[j]='4';
else if(a[j]=='J'||a[j]=='K'||a[j]=='L'||a[j]=='5')
a[j]='5';
else if(a[j]=='M'||a[j]=='N'||a[j]=='O'||a[j]=='6')
a[j]='6';
else if(a[j]=='P'||a[j]=='R'||a[j]=='S'||a[j]=='7')
a[j]='7';
else if(a[j]=='T'||a[j]=='U'||a[j]=='V'||a[j]=='8')
a[j]='8';
else if(a[j]=='W'||a[j]=='X'||a[j]=='Y'||a[j]=='9')
a[j]='9';
else if(a[j]=='0'||a[j]=='1')
a[j]=a[j];
else
return 0;
}
return 1;
}
int cmp(const void* a,const void* b)
{
return *(unsigned long long*)a>*(unsigned long long*)b?1:-1;
}
int main()
{
int i,j,j1,j2,j3,j4,c1;
int max;
max=0;
char c2[10];
char a,b;
unsigned long j5;
unsigned long long number1[100000]={0};;
j2=0;
j4=0;
struct hashmap *barrel[2000];
memset(barrel,0,2000*sizeof(struct hashmap *));
scanf("%d",&i);
while(i--)
{
char c[300],c1[300];
int z,z1;
scanf("%s",c);
rmhyphen(c,c1);
if(ctoi(c1)==1)
{
j=atoi(c1);
j5=j*618;
j5=j5%1000;
j1=(int)j5*1024/1000;
max=max>j1?max:j1;
if(barrel[j1]==0)
{
struct hashmap * m=(struct hashmap*)malloc(sizeof(struct hashmap));
struct map * m1=(struct map*)malloc(sizeof(struct map));
m->hash[0]=m1;
barrel[j1]=m;
m->hash[0]->phone=j;
m->hash[0]->size=1;
m->size=1;
}
else
{
for(z1=0;z1<barrel[j1]->size;z1++)
{
if(barrel[j1]->hash[z1]->phone==j)
{
barrel[j1]->hash[z1]->size++;
j2=1;
}
}
if(j2==0)
{
//struct hashmap * m=(struct hashmap*)calloc(1,sizeof(struct hashmap));
struct map * m1=(struct map*)malloc(sizeof(struct map));
barrel[j1]->hash[z1]=m1;
//m->hash[z1]=m1;
//barrel[j1]=m;
barrel[j1]->hash[z1]->phone=j;
barrel[j1]->hash[z1]->size=1;
barrel[j1]->size++;
}
else
j2=0;
}
}
}
for(j2=0;j2<=max;j2++)
{
if(barrel[j2]!=0)
{
for(j3=0;j3<barrel[j2]->size;j3++)
{
if(barrel[j2]->hash[j3]->size!=1)
{
number1[j4]=((unsigned long long )barrel[j2]->hash[j3]->phone)<<20;
number1[j4]=number1[j4]+(unsigned long long)barrel[j2]->hash[j3]->size;
free(barrel[j2]->hash[j3]);
//free(barrel[j2]);
j4++;
}
else
free(barrel[j2]->hash[j3]);
}
free(barrel[j2]);
}
}
qsort(number1,j4,sizeof(number1[0]),cmp);
unsigned long long q;
unsigned long long q1;
if(j4!=0)
{
for(j2=0;j2<j4;j2++)
{
q=number1[j2]>>20<<20;
q=number1[j2]-q;
q1=number1[j2]>>20;
c1=(int)q1;
sprintf(c2,"%07d",c1);
a=c2[3];
c2[3]='-';
for(c1=4;c1<8;c1++)
{
b=c2[c1];
c2[c1]=a;
a=b;
}
c2[8]=0;
//cout<<c2<<' '<<q<<endl;
printf("%s %u\n",c2,q);
//printf(" %u\n",q);
}
}
else
//cout<<"No duplicates."<<endl;
{printf("No duplicates.");}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator