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

求助..拜托了.有注释..想死了..先是TLE..改用快速排序后就出错了..弄了2天了....还是WA!!!!!!!

Posted by scutlili at 2008-12-06 17:06:58 on Problem 1002 and last updated at 2008-12-06 17:08:14
#include<iostream>
#include<iomanip>
using namespace std;
//转换
int map(char p)
{	if(p=='A'||p=='B'||p=='C') return 2;
	else if(p=='D'||p=='E'||p=='F') return 3;
	else if(p=='G'||p=='H'||p=='I') return 4;
	else if(p=='J'||p=='K'||p=='L') return 5;
	else if(p=='M'||p=='N'||p=='O') return 6;
	else if(p=='P'||p=='S'||p=='R') return 7;
	else if(p=='T'||p=='U'||p=='V') return 8;
	else if(p=='W'||p=='X'||p=='Y') return 9;
}
//快速排序
void run(int * pA,int left,int right)
{int i,j,middle,temp;
i=left;j=right;
middle=pA[(i+j)/2];
do
{
	while((pA[i]<middle)&&(i<right))
	i++; 
	while((pA[j]>middle) && (j>left))
	j--;
if(i<=j)
{temp=pA[i];pA[i]=pA[j];pA[j]=temp;i++;j--;}
}while(i<=j);
if(left<j) run(pA,left,j);
if(right>i) run(pA,i,right);
}

void QuickSort(int* pA,int Count)
{
run(pA,0,Count-1);
}


int main()
{char p;int static k=0;int i,ptelnumA[50000]={-100},ptelnum[50000][2]={-55},num,re=0,work=0;
//输入数据
cin>>num;
for(i=0;i<num;i++)
{ptelnumA[i]=0;
	for(k=0;k<7;k++)
	{cin>>p;
	if(p=='-') k--;
		else if(p>=48&&p<=57) {ptelnumA[i]*=10;ptelnumA[i]+=p-48;}
	else {ptelnumA[i]*=10;ptelnumA[i]+=map(p);}
	}
}

QuickSort(ptelnumA,num);

//记录重复的部分
ptelnum[0][0]=ptelnumA[0];
ptelnum[0][1]=0;
for(i=1,k=1;i<num;i++)
{
	if(ptelnumA[i]==ptelnum[k-1][0]) {ptelnum[k-1][1]++;re=1;}
	else{ptelnum[k][0]=ptelnumA[i];ptelnum[k][1]=0;k++;}
}

if(re)//有重复的输出
for(i=0;i<k+1;i++)
{if(ptelnum[i][1])
cout<<setfill('0')<<setw(3)<<ptelnum[i][0]/10000
	<<'-'<<setfill('0')<<setw(4)<<ptelnum[i][0]%10000<<' '<<ptelnum[i][1]+1<<'\n';
}
//没有重复的输出
else cout<<"No duplicates.";


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