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 lnnulc2005 at 2008-03-21 12:24:22 on Problem 1002
我都已经测试了好多数据了,都对啊,但总说我WA,我就不知道到底是哪有问题了,请大牛帮我看看问题,代码附上
#include <iostream>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>


char Tel[8][3] = {{'A','B','C'},{'D','E','F'},{'G','H','I'},{'J','K','L'},{'M','N','O'},{'P','R','S'},{'T','U','V'},{'W','X','Y'}};
int *Translate_Over_Tel;

int Translate_tel_letter(char *letter,int &real_tel)
{
	char *ptr,*first;	
	ptr = &Tel[0][0];
	first = &Tel[0][0];

	while(*ptr!=*letter&&*ptr!='\0')
		ptr++;

	real_tel = (ptr-first)/3+2;	
	return 0;
}

int judgeissame(int *string1,int *string2,int i)
{
	for(int j=0;j<i;j++)
	{
		while(*(string1+j*8)==*string2)
		{
			string1++;
			string2++;
		}
		
		if(*string2==0)
			return j;
	}

	return -1;
}

int taxis(int *string,int i)
{
	struct MIN
	{
		char flag;		
		float sum;
	};

	int *serial = (int *)malloc(i*sizeof(int));

	struct MIN *min = (struct MIN *)malloc(i*sizeof(MIN));

	for(int n=0;n<i;n++)
	{
		min[n].sum = 0.0;
		min[n].flag = true;
	}

	for(int m=0;m<i;m++)
	{
		for(int n=0;n<7;n++)
		{
			min[m].sum += string[n+m*8]*(float)pow(10.0,3-n);
		}			
	}

	for(int loop=0;loop<i;loop++)
	{
		int minsum = 100000;
		for(int j=0;j<i;j++)
		{
			if((min[j].sum<minsum)&&min[j].flag)
			{
				minsum = min[j].sum;
				serial[loop] = j;
			}
		}
		min[serial[loop]].flag = false;		
	}	
	
	////////////////////////////////////////////cout

	int number=0;
	std::cout<<'\n';

	for(int j=0;j<i;j++)
	{
		if(string[7+serial[j]*8]>1)
		{
			number=1;
			for(int loop=0;loop<8;loop++)
			{
				std::cout<<string[loop+serial[j]*8];
				if(loop==2)
					std::cout<<"-";
				if(loop==6)
					std::cout<<" ";
				if(loop==7)
					std::cout<<'\n';
			}
		}
	}

	if(number==0)
		std::cout<<"No duplicates."<<std::endl;

	free(serial);
	free(min);
	return 0;
}


int main()
{
	char tel_letter[300];
	int temporary[8];
	char *ptr;	
	int n,i=0,real_tel,m,jud,I=1;

	std::cin>>n;
	Translate_Over_Tel =(int *)malloc(n*8*sizeof(int));

	while(I<=n)
	{
		std::cin>>tel_letter;	
		m = 0;	
		memset(temporary,0,sizeof(temporary));
		ptr = tel_letter;
		while(*ptr!='\0')
		{
			if(isupper(*ptr)&&*ptr!='Q'&&*ptr!='Z')
			{
				Translate_tel_letter(ptr,real_tel);
				temporary[m] = real_tel;			
				m++;
			}
			if(isdigit(*ptr))
			{
				int int_tel;
				int_tel = *ptr-'0';
				temporary[m] = int_tel;				
				m++;
			}			
			ptr++;
		}

		if(I>1)
		{
			jud=judgeissame(Translate_Over_Tel,temporary,i);

			if(jud==-1)
			{
				for(int loop=0;loop<7;loop++)
				{
					Translate_Over_Tel[loop+i*8] = temporary[loop];
				}
				Translate_Over_Tel[7+i*8]=1;
				i++;
			}
			if(jud!=-1)
			{
				Translate_Over_Tel[7+jud*8]++;
			}
		}
		else if(I==1)
		{
			for(int loop=0;loop<7;loop++)
				{
					Translate_Over_Tel[loop] = temporary[loop];
				}
				Translate_Over_Tel[7]=1;
				i++;
		}
			
		I++;		
	}

	taxis(Translate_Over_Tel,i);	

	free(Translate_Over_Tel);

	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