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

求助 一直WA。。

Posted by h312903294 at 2008-10-05 20:55:16 on Problem 1002
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
void swap(int* a,int* b)
{
	int temp;
	temp=*a;
	*a=*b;
	*b=temp;
}
int partition(int a[],int i,int j)
{
	int k,h;
	int val;
	h=i;
	val=a[i];
	for(k=i+1;k<=j;k++)
		if(a[k]<val)
		{
			h=h+1;
			swap(a+h,a+k);
		}
	swap(a+i,a+h);	
	return h;
}
void quicksort(int a[],int i,int j)
{
	int p;
	if(i<j)
	{
		p=partition(a,i,j);
		quicksort(a,i,p-1);
		quicksort(a,p+1,j);
	}
}
	
char a[100000][50];
int b[100000];
int main()
{
	int i,j,k,m,n,tot,sign=0,temp=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{   
		scanf("%s",a+i);
	}
	for(i=0;i<n;i++)
	{
		m=strlen(a[i]);
		for(j=0;j<m;j++)
		{
			if(a[i][j]!='-')
				continue;
			k=j;
			for(;k<m;k++)
			{
				a[i][k]=a[i][k+1];
			}
			j=-1;
		}
		
	}
	for(i=0;i<n;i++)
	{
		m=strlen(a[i]);
		for(j=0;j<m;j++)
		{
			switch(a[i][j])
			{
				case'A':
				case'B':
				case'C':
					a[i][j]='2';
                    break;					
				case'D':
				case'E':
				case'F':
					a[i][j]='3';
					break;
				case'G':
				case'H':
				case'I':
					a[i][j]='4';
					break;
				case'J':
				case'K':
				case'L':
					a[i][j]='5';
					break;
				case'M':
				case'N':
				case'O':
					a[i][j]='6';
					break;
				case'P':
				case'R':
				case'S':
					a[i][j]='7';
					break;
				case'T':
				case'U':
				case'V':
					a[i][j]='8';
					break;
				case'W':
				case'X':
				case'Y':
					a[i][j]='9';
					break;
				default:
					break;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		m=atol(a[i]);
		b[i]=m;
	}
	quicksort(b,0,n-1);
	for(i=0;i<n;i++)
	{
		tot=1;
		m=b[i];
		if(m!=-1)
		{
			for(j=i+1;j<n;j++)
		    {
				if(m==b[j])
			    {
					tot++;
					b[j]=-1;
			    }
			}
			
		   if(tot!=1) 		   
		   {
			   sign=1;
			   for(j=0;j<8;j++)
			   {
				   if(j==3)
					   printf("-");
				   if(j<3)
				   {
						temp=b[i]/(int)powf(10.0,(float)(6-j));
						printf("%c",temp+48);
						b[i]=b[i]-temp*(int)powf(10.0,(float)(6-j));
				   }
				   if(j>3)
				   {
					    temp=b[i]/(int)powf(10.0,(float)(7-j));
						printf("%c",temp+48);
						b[i]=b[i]-temp*(int)powf(10.0,(float)(7-j)); 
				   }
			   }
			   printf(" %d\n",tot);
		   }
		   
		}
	}
	if(sign==0)
		printf("No duplicates.\n");
	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