ACM PKU 1002 487-3279 较复杂字符串比较操作

http://acm.pku.edu.cn/JudgeOnline/problem?id=1002

读入字符串-将字符串统一格式- qsort- 查找重复并记录-输出
Source Code

Problem: 
1002  User: lnmm 
Memory: 944K  Time: 529MS 
Language: C
++  Result: Accepted 

Source Code 
#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
char map[]="22233344455566677778889999";
char str[80],telNumber[100000][9];
int compare(const void *p1,const void *p2)
{
    
return(strcmp((char*)p1,(char*)p2));
}


void standardizeTel(int n)
{
    
int j,k;
    k
=-1;j=-1;
    
while(k<8)
    
{
    
    j
++;
    
if(str[j]=='-'continue;
    k
++;
    
if(k==3){telNumber[n][k]='-';k++;}
        
if(str[j]>='A'&&str[j]<='Z'){telNumber[n][k]=map[str[j]-'A'];continue;}
    telNumber[n][k]
=str[j];
    }



     telNumber[n][
8]='\0';
     
return;
}


void main()
{
    
int n,i,j;
    
bool noduplicate;
    scanf(
"%d",&n);
    
for(i=0;i<n;i++)
    
{
        scanf(
"%s",str);
        standardizeTel(i);

    }

    qsort(telNumber,n,
9,compare);
    noduplicate
=true;
    i
=0;
    
while(i<n)
    
{
        j
=i;
        i
++;
        
while((i<n)&&strcmp(telNumber[i],telNumber[j])==0)i++;
        
if(i-j>1)
        
{
            printf(
"%s %d\n",telNumber[j],i-j);
            noduplicate
=false;

        }

    
    }

        
if(noduplicate==true)
            printf(
"No duplicates.\n");
}

posted on 2007-11-13 15:06 流牛ζ木马 阅读(2333) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年9月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

导航

统计

公告

MY Email/MSN :mars1021@163.com QQ : 27402040 流牛ζ木马

常用链接

留言簿(6)

随笔档案

相册

搜索

最新随笔

最新评论

阅读排行榜

评论排行榜