• 博客访问： 989269
• 博文数量： 153
• 博客积分： 4195
• 博客等级： 上校
• 技术积分： 2631
• 用 户 组： 普通用户
• 注册时间： 2009-06-22 11:32

2012年（7）

2010年（35）

2009年（111）

2009-11-15 22:29:21

#include
#include
struct tel_number
{
char a[20];
};
struct eight_number
{
char b[8];
};
struct not_equal
{
char b[8];
int count;
};

char change_number(char num)
{
char real_number;
switch(num)
{
case '0':real_number = '0';break;
case '1':real_number = '1';break;
case 'A': case 'B':case 'C': case '2': real_number = '2';break;
case 'D': case 'E':case 'F': case '3': real_number = '3';break;
case 'G': case 'H':case 'I': case '4': real_number = '4';break;
case 'J': case 'K':case 'L': case '5': real_number = '5';break;
case 'M': case 'N':case 'O': case '6': real_number = '6';break;
case 'P': case 'R':case 'S': case '7': real_number = '7';break;
case 'T': case 'U':case 'V': case '8': real_number = '8';break;
case 'W': case 'X':case 'Y': case '9': real_number = '9';break;
default: real_number = 'z';
}
return real_number;
}

int main()
{
int num,seq_num;
struct tel_number *seq;
struct eight_number *real;
int k,m;
int count = 0;
scanf("%d%c",&num,&k);
seq = malloc(num*sizeof(struct tel_number));
real = malloc(num*sizeof(struct eight_number));
seq_num = 0;
int old_num = num;
int not_equal_count = 0;
while(num)
{
int i = 0;
int j = 0;
char changed;
while(scanf("%c", &((seq+seq_num)->a[i])),(seq+seq_num)->a[i] != '\n')
{
changed = change_number((seq+seq_num)->a[i]);
// printf("old is %c new is %c\n",(seq+seq_num)->a[i],changed);
if(changed != 'z')
{
(real+seq_num)->b[j] = changed;
j++;
}
i++;
}
num--;
//printf("num is %d\n",num);
seq_num++;
}
struct not_equal *c = malloc(old_num*sizeof(struct not_equal));
memset(c,0x0,old_num*sizeof(struct not_equal));
int c_total_count = 0;
// (c->b) = (real->b);
memcpy(c->b,real->b,8);
c->count = 1;
c_total_count++;
int i,j;
for(i = 1; i < old_num; i++)
for(j = 0; j < c_total_count; j++)
if(strcmp((real+i)->b,(c+j)->b) == 0)
{
(c+j)->count++;
break;
}
else
{
if(j == c_total_count-1)
{
//     (c+j+1)->b = (real+i)->b;
memcpy((c+j+1)->b,(real+i)->b,8);
(c+j+1)->count++;
c_total_count++;
break;
}
}
for(j = 0; j < c_total_count; j++)
if((c+j)->count > 1)
{
for(i = 0; i < 3; i++)
printf("%c",(c+j)->b[i]);
printf("-");
for(;i<7;i++)
printf("%c",(c+j)->b[i]);
printf(" %d\n",(c+j)->count);
}
free(seq);
free(real);
free(c);
return 0;
}
/*以下没用，只是编写过程中对一些小方面的测试。
#ifdef DEBUG
printf("the value is %d\n",strcmp(real->b,(real+1)->b));
printf("%s\n",&real->b);
#endif
*/
/*
struct b
{
int value;
int count;
};
int cmp(int a ,int b)
{
if(a == b)
return 0;
if(a > b)
return 1;
else
return -1;
}
int main()
{
int a[10] = {1,1,2,4,5,5,4,3,1,1};
int i,j;
struct b *c = malloc(10*sizeof(struct b));
memset(c,0x0,10*sizeof(struct b));
int c_total_count = 0;
c->value = a[0];
c->count = 1;
c_total_count++;
for(i = 1; i < 10; i++)
for(j = 0; j < c_total_count; j++)
if(cmp(a[i],(c+j)->value) == 0)
{
(c+j)->count++;
break;
}
else
{
if(j == c_total_count-1)
{
(c+j+1)->value = a[i];
(c+j+1)->count++;
c_total_count++;
break;
}
}
for(j = 0; j < c_total_count; j++)
if((c+j)->count > 1)
printf("%d is %d times\n",(c+j)->value,(c+j)->count);
}
*/

0