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

为何老是“wrong answer",望高手指点?(程序见里)

Posted by A0317573 at 2004-02-12 20:49:40 on Problem 1002
#include <iostream.h>
#include <string.h>

void main()
{
	char *number[20],*tel[20];
	int same=0,t=0,telsame[20];
	long n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		number[i]=new char[20];
		tel[i]=new char[20];
		tel[i]=NULL;
		cin>>number[i];
	}

	for(int k=0;k<n;k++)
	{
		char ntmp[20];
		for(int l=0;l<20;l++)
			ntmp[l]=*(number[k]+l);

		for(i=0;i<20;i++)
		{			
			char tmp=*(number[k]+i);
			if(tmp>='A' && tmp<='C') ntmp[i]='2';
			if(tmp>='D' && tmp<='F') ntmp[i]='3';
			if(tmp>='G' && tmp<='I') ntmp[i]='4';
			if(tmp>='J' && tmp<='L') ntmp[i]='5';
			if(tmp>='M' && tmp<='O') ntmp[i]='6';
			if(tmp>='P' && tmp<='S' && tmp!='Q') ntmp[i]='7';
			if(tmp>='T' && tmp<='V') ntmp[i]='8';
			if(tmp>='W' && tmp<='Y') ntmp[i]='9';
		}

		for(l=0;l<20;l++)
		{
			if(ntmp[l]>'9' || ntmp[l]<'0')
			{
				for(int j=l;j<19;j++)
					ntmp[j]=ntmp[j+1];
			}
		}
		*number[k]=ntmp[0];
		*(number[k]+1)=ntmp[1];
		*(number[k]+2)=ntmp[2];
		*(number[k]+3)='-';
		*(number[k]+4)=ntmp[3];
		*(number[k]+5)=ntmp[4];
		*(number[k]+6)=ntmp[5];
		*(number[k]+7)=ntmp[6];
		for(l=8;l<20;l++)
			*(number[k]+l)='\0';
		
	}

	for(k=0;k<n;k++)
	{   
		if(number[k]!=NULL)
		{   same=1;
			for(int j=k+1;j<n;j++)
				for(int l=0;l<8;l++)
				{
					if(number[j]!=NULL)
					{
					if(*(number[k]+l)!=*(number[j]+l)) break;
                    if(l==7) 
					{
						same++;
						delete []number[j];
						number[j]=NULL;
					}
					}
				}

		    if(same!=1)
			{
			
				tel[t]=number[k];
				telsame[t]=same;
				t++;

			}
			else
			{
				delete []number[k];
				number[k]=NULL;
			}

		}
	}

	if(tel[0]==NULL)
	{
		cout<<"No duplicates\n";
		return;
	}

    t=0;
	while(tel[t]!=NULL)
	{
		t++;
	}

	char *p;
	int temps;
	bool flag;

    do
	{
		flag=0;
		for(k=0;k<t-1;k++)
			if(strcmp(tel[k],tel[k+1])==1)
			{
				p=tel[k];
				tel[k]=tel[k+1];
				tel[k+1]=p;
				temps=telsame[k];
				telsame[k]=telsame[k+1];
				telsame[k+1]=temps;
				flag=1;
											
			}
	t--;
	}while(flag==1);
    
	t=0;
	while(tel[t]!=NULL)
	{
		cout<<tel[t]<<" "<<telsame[t]<<endl;
		t++;
	}
}
	


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