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 zhanghua at 2007-05-18 23:05:45 on Problem 1002
#include<stdio.h>
#include<string.h>
typedef struct item
{
	long count;
	char number[100];
	struct item *rchild;
	struct item*lchild;
}node,*link;
int map[30];
void init()
{
	map['A'-'A']=2;
 	map['B'-'A']=2;
 	map['C'-'A']=2;
 	map['D'-'A']=3;
 	map['E'-'A']=3;
 	map['F'-'A']=3;
 	map['G'-'A']=4;
  	map['H'-'A']=4;
  	map['I'-'A']=4;
  	map['J'-'A']=5;
 	map['K'-'A']=5;
 	map['L'-'A']=5;
 	map['M'-'A']=6;
	map['N'-'A']=6;
	map['O'-'A']=6;
	map['P'-'A']=7;
	map['Q'-'A']=7;
	map['R'-'A']=7;
	map['S'-'A']=7;
	map['T'-'A']=8;
	map['U'-'A']=8;
	map['U'-'A']=8;
	map['W'-'A']=9;
	map['X'-'A']=9;
	map['Y'-'A']=9;
	map['Z'-'A']=9;

}
void stringprocess(char b[])
{
	int i=0,len=0,len2,j=0;
	char a[100],s;
	while(b[i]!='\0')
	{
		s=b[i];
		if(j==3)
		{
			a[j]='-';
			j++;
                       	continue;
		}
		if(s=='-')
		{
                           i++;
			continue;
		}
		else if(s>='0'&&s<='9')
		{
			a[j]=s;
			j++;
			i++;
		}
		else
		{
			a[j]=map[s-'A']+48;
			j++;
			i++;
		}
	}
        a[j]='\0';
	strcpy(b,a);
}
int create_bttree(link * bt,long k)
{
	char temp[100];
	long i,flag=0,nodes;
	link p,pre,newnode;
	gets(temp);
	stringprocess(temp);
	*bt=(link)malloc(sizeof(node));
	strcpy((*bt)->number,temp);
	(*bt)->count=1;
	(*bt)->rchild=NULL;
	(*bt)->lchild=NULL;
	nodes=1;
	for(i=1;i<k;i++)
	{
		gets(temp);
		stringprocess(temp);
		p=*bt;
		flag=0;
		while(p!=NULL)
		{
			if(strcmp(p->number,temp)>0)
			{
				pre=p;
				p=p->lchild;
				flag=-1;
			}
			else if(strcmp(p->number,temp)<0)
			{
				pre=p;
				p=p->rchild;
				flag=1;
			}
			else
			{
				flag=0;
				p->count++;
                                     break;
			}
		}
		if(flag==0){continue;}
		else
		{
			nodes++;
			newnode=(link)malloc(sizeof(node));
			newnode->count=1;
			strcpy(newnode->number,temp);
			newnode->lchild=NULL;
			newnode->rchild=NULL;
			if(flag==-1){pre->lchild=newnode;}
			else if(flag==1){pre->rchild=newnode;}
		}
	}
	if(nodes==k){return 0;}
	else return 1;
}
int inorder(link bt)
{
	if(bt!=NULL)
	{
		inorder(bt->lchild);
                  if(bt->count>1)
		printf("%s %ld\n",bt->number,bt->count);
		inorder(bt->rchild);
	}
}
main()
{
	long n;
         int i=0;
	link btr;
	 scanf("%ld",&n);
	 getchar();
	init();
	i=create_bttree(&btr,n);
	if(i==0)
	{
		printf("No duplicates.\n");
	}
	else
	{
		inorder(btr);
	}
}

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