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 sangyongjia at 2014-06-17 22:41:17 on Problem 1002
#include"stdio.h"
#define LENGTH 50

void adjust_heap(int *input, int root, int size)
{
	int swap=0;
	int left=2*root+1;
	int right=2*root+2;
	int largest=root;
	while(root<size)
	{
		if((left<size) || (right<size))
		{
			if((left<size) && (input[largest]<input[left]))
			{
				largest=left;
			}
			if((right<size) && (input[largest]<input[right]))
			{
				largest=right;
			}
		}
		if(largest!=root)
		{
			swap=input[largest];
			input[largest]=input[root];
			input[root]=swap;

			left=2*largest+1;
			right=2*largest+2;
			root=largest;	
		}
		else
		{
			break;
		}
	}
}

void build_maxheap(int *input,int size)
{
	int i=0;
	int lastend_root=size/2-1;
	for(i=lastend_root;i>=0;i--)
	{
		adjust_heap(input,i,size);
	}
}

void heap_sort(int *input,int size)
{
	int swap=0;
	build_maxheap(input,size);

	while(size>1)
	{
		swap=input[0];
		input[0]=input[size-1];
		input[size-1]=swap;
		size--;
		adjust_heap(input,0,size);
	}
}

void main()
{
	int n=0;
	int temp=0;
	int count=0;
	char printed=0;
	int i=0,j=0;
	char input[LENGTH];
	int mid_output[100000]={0};

	int map_table[100];
	map_table['0']=0;
	map_table['1']=1;
	map_table['2']=map_table['A']=map_table['B']=map_table['C']=2;
	map_table['3']=map_table['D']=map_table['E']=map_table['F']=3;
	map_table['4']=map_table['G']=map_table['H']=map_table['I']=4;
	map_table['5']=map_table['J']=map_table['K']=map_table['L']=5;
	map_table['6']=map_table['M']=map_table['N']=map_table['O']=6;
	map_table['7']=map_table['P']=map_table['R']=map_table['S']=7;
	map_table['8']=map_table['T']=map_table['U']=map_table['V']=8;
	map_table['9']=map_table['W']=map_table['X']=map_table['Y']=9;

	scanf("%d",&n);
	for(i=0; i<n; i++)
	{
		scanf("%s",input);
		j=0;
		while(input[j])
		{
			if(((input[j]>='0') && (input[j]<='9')) || ((input[j]>='A') && (input[j]<='Z')))
			{
				mid_output[i]=10*mid_output[i]+map_table[input[j]];
				j++;
			}
			else
			{
				j++;
			}
		}
	}
	heap_sort(mid_output,n);
	for(i=0;i<n;i++)
	{
		printf("%d ",mid_output[i]);
	}

	for(i=0;i<n;)
	{
		temp=mid_output[i];
		while(temp==mid_output[i])
		{
			count++;
			i++;
		}
		if(count>=2)
		{
			printf("%d-",temp/10000);
			printf("%d %d\n",temp%10000,count);
			printed=1;
			count=0;
		}
		else
		{
			count=0;
		}		
	}
	
	if(0==printed)
	{
		printf("No duplicates\n");
	}
}

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