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

很怪异,一直RuntimeError。能帮我看看吗?

Posted by erikchen1985 at 2009-01-21 21:33:29 on Problem 1002 and last updated at 2009-01-21 21:46:53
#include <iostream>
using namespace std;

int stand[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1};

int Partition(int **a,int low,int high)
{
	int pivotkey[1][2];
	pivotkey[0][0]=a[low][0];
	pivotkey[0][1]=a[low][1];
	
	while(low<high)
	{
		while( (low<high) && (a[high][0]>=pivotkey[0][0]) )	--high;
		a[low][0]=a[high][0];
		a[low][1]=a[high][1];

		while( (low<high) && (a[low][0]<=pivotkey[0][0]) ) ++low;
		a[high]=a[low];
	}

	a[low][0]=pivotkey[0][0];
	a[low][1]=pivotkey[0][1];

	return low;
}

void QSort(int **a,int low,int high)
{

	int p=Partition(a,low,high);

	while(p>low)
	{
		p=Partition(a,low,p-1);
	}

	while(p<high)
	{
		p=Partition(a,p+1,high);
	}
}

int main()
{
	int i;
	freopen("in.txt","r",stdin);

	int n;
	cin>>n;

	int amount=n;
	
	int **a=new int*[amount+1];
	for(i=0;i<amount+1;i++)
	{
		a[i]=new int[2];
	}

	for(i=0;i<amount+1;i++)
	{
		a[i][0]=-1;
		a[i][1]=-1;
	}

	

	while(n--)
	{
		int tmp=0;	//标准化后的值
		int h=0;
		int d=1000000;
		while(h<7)
		{
			char chr;
			cin>>chr;

			if( (chr>=48) && (chr<=57) )
			{
				tmp+=(chr-48)*d;
				d/=10;
				h++;
			}
			else if( (chr>=65) && (chr<=90) )
			{
				tmp+=stand[chr-65]*d;
				d/=10;
				h++;
			}
		}
		
		//把数一个一个插入到二叉搜索树
		bool flag=true;
			
		int dup=0;
		int cur=1;
		while(flag)
		{
			if(a[cur][0]==-1)
			{
				a[cur][0]=tmp;
				a[cur][1]=0;

				flag=false;

				dup++;		//有多少个不同的数
			}
			else if(a[cur][0]==tmp)
			{
				a[cur][1]++;

				flag=false;
			}
			else if(a[cur][0]>tmp)
			{
				cur*=2;
			}
			else
			{
				cur=cur*2+1;
			}
		}

	}
/*
	for(i=0;i<amount;i++)
	{
		int p=a[i][0]/10000;
		cout<<p<<"-"<<a[i][0]-p*10000<<" "<<a[i][1]+1<<endl;
	}

*/
	//第一步,完成完全二叉树,随便判断是否为No duplicates.

	
	bool flag=false;
	
	int **b=new int*[amount+1];
	for(i=0;i<amount+1;i++)
	{
		b[i]=new int[2];
	}

	int h=0;
	for(i=0;i<amount+1;i++)
	{
		if(a[i][1]>0)
		{
			b[h][0]=a[i][0];
			b[h][1]=a[i][1];

			h++;

			flag=true;
		}
	}

	if(flag==false)
	{
		cout<<"No duplicates.";
		return 0;
	}

  
	QSort(b,0,h-1);


	for(i=0;i<h;i++)
	{
		int p=b[i][0]/10000;
		
		int p2=b[i][0]-p*10000;

		int c=b[i][1]+1;

		cout<<p<<"-";
		cout<<p2;
		cout<<" ";
		cout<<c;
		cout<<endl;
	}

	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