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

Re:qsort的cmp函数应该怎么改?

Posted by haining at 2012-07-04 10:17:49 on Problem 1002
In Reply To:qsort的cmp函数应该怎么改? Posted by:8085 at 2006-03-11 17:28:51
> #include <iostream.h>
> #include <string.h>
> #include <stdlib.h>
> struct tel
> {
> 		int cishu;
> 		char telnum[16];
> }phone[100001];
> int cmp(const void * a,const void * b)
> {
> 		return strcmp( *(tel*)a->telnum,*(tel*)b->telnum);
> }
> void main()
> {
> 	int num,i=0,len,j,k;
> 	char con[]="22233344455566677778889999";
> 	cin >>num;
> 	for(;i<num;i++)
> 	{
> 		cin >>phone[i].telnum;
> 		phone[i].cishu=1;;
> 		len=strlen(phone[i].telnum);
> 		for(j=0;j<len;j++)
> 		{
> 			if(phone[i].telnum[j]=='-')
> 			{
> 				for(k=j;k<len;k++)
> 					phone[i].telnum[k]=phone[i].telnum[k+1];
> 				len--;     
> 			}
> 			if(phone[i].telnum[j]>='A'&&phone[i].telnum[j]<='Y')
> 				phone[i].telnum[j]=con[phone[i].telnum[j]-'A'];
> 		}
> 	}
> 	qsort(phone,num,sizeof(phone[0]),cmp);
> 	for(j=0;j<num;j++)
> 		{
> 			if(phone[j].cishu>1)
> 			{
> 			for(int x=0;x<7;x++)
> 				{
> 					if(x==3)
> 						cout <<'-';
> 					cout <<phone[j].telnum[x];
> 				}
> 			cout <<' '<<phone[j].cishu<<endl;
> 			
> 			}
> 		}
> 	if(k==0) cout <<"No duplicates."<<endl;
> 	
> }
> 
> 

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