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 |
好心的大牛,帮小弟一个忙吧。为什么我的程序中qsort不起作用啊。#include<iostream> #include<stdlib.h> 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((void*)c,n,sizeof(c[0]),cmp); 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator