Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么我的答案是错的,貌似排序出了问题。好心的大牛帮帮忙吧。求你们了。

Posted by liuhighway at 2010-02-15 15:32:08 on Problem 1002
我输出的答案是
888-4567 3
487-3279 4
310-1010 2
求求你们,帮我一下。
#include<iostream>
using namespace std;
int cmp(const void *w,const void *y)
{return (strcmp((char*)w,(char*)y));}
int main()
{int n,i,j,k,e;
char **a=NULL, map[]="22233344455566677778889999";char **c=NULL;
cin>>n;getchar();a=new char*[n];c=new char *[n];int *d=new int [n];
for(i=0;i<n;i++)
{a[i]=new char [100];c[i]=new char[9];d[i]=1;}
for(i=0;i<n;i++)
{cin>>a[i];}
for(i=0;i<n;i++)
{
for(j=0,k=0;a[i][j]!='\0'&&j<100;j++)
{if(k==3){c[i][k]='-';k++;j--;continue;}	
if(a[i][j]>='A'&&a[i][j]<='Z'){c[i][k]=map[a[i][j]-'A'];k++;continue;}
if(a[i][j]>='0'&&a[i][j]<='9'){c[i][k]=a[i][j];k++;continue;}
}c[i][k]='\0';
}
qsort(c,n,sizeof(c[0]),cmp);
for(j=0;j<n;j++)
{cout<<c[j]<<endl;}
for( e=0,i=0;i<n-1;i++)
{if(d[i]!=0)
{for(j=i+1;j<n;j++)
{if(strcmp(c[i],c[j])==0){d[i]++;d[j]=0;e++;}
}
}
}
if(e==0)cout<<"No duplicates."<<endl;
else
{for(i=0;i<n;i++)
{if(d[i]!=0&&d[i]!=1)cout<<c[i]<<" "<<d[i]<<endl;}
}
return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator