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 thief at 2007-01-17 21:26:57
1002老是runtime error
#include <iostream>
#include <iomanip>
using namespace std;
struct tree
{
	int s,f;
	tree *l,*r;
};
int tr(char d[])
{
	int l=strlen(d);
	int i,s=0;
	for (i=0;i<l;i++)
	{
		if (d[i]=='-') continue;
		if (isdigit(d[i])) {s=s*10+(d[i]-'0');continue;}
		else 
		{
			if (d[i]<'Q') {s=s*10+(d[i]-'A')/3+2;continue;}
			else s=s*10+(d[i]-'Q')/3+7;
		}
	}
	return s;
}
void insert (tree *&root,tree *p);

	
void play( tree *root,int &cs)
{
	if (root==NULL) return;
	play (root->l,cs);
	if (root->f>1)
	{
	    int 	r=root->s/10000;
		cout<<setfill('0');
		cout<<setw(3)<<r<<'-'<<setw(4)<<root->s%10000<<' '<<root->f<<endl;		
		cs++;
	}
	play (root->r,cs);
}
int main()
{
	int n,i,sz,cs=0;
	tree *p=NULL,*root=NULL;
	char d[20];
	cin>>n;
	for (i=1;i<=n;i++)
	{
	cin>>d;
	sz=tr(d);
	p=new tree;
	p->s=sz;
	p->f=1;p->l=NULL;p->r=NULL;
	insert (root,p);
	}
	play (root,cs);
	if (cs==0) cout<<"No duplicates."<<endl;
	return 0;
}
void insert (tree *&root,tree *p)
{
	if (root==NULL) root=p;
	else
	{
	    if (root->s==p->s) root->f++;
		else 
		{
			if (root->s>p->s) insert(root->l,p);
			else insert (root->r,p);
		}
    	
	}	
	
}

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