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

为啥总是runtime error啊 请教大牛~~

Posted by BIRLYO at 2012-06-27 19:26:24 on Problem 1602
RT 代码如下,临平膜拜~

#include <stdio.h>

int bucketsort(char s[100][3], int n)
{
	int i;
	int count[26] = {0};
	int next[26] = {0};
	int index =0;
	int first = 1;
	if(n == 1)
		first = 0;
	int secondindex = s[first][0] - 97;
	char tmp[100][3] = {0};
	for(i =0;i<n;i++)
	{
		index = s[i][0] - 97;
		count[index]++;
		tmp[i][0] = s[i][0];
		tmp[i][1] = s[i][1];
		tmp[i][2] = s[i][2];
	}
	for(i=1;i<26;i++)
		next[i] = count[i-1]+next[i-1];
	first = next[secondindex]+1;
	for(i =0;i<n;i++)
	{
		index = tmp[i][0] - 97;
		s[next[index]][0] = tmp[i][0];
		s[next[index]][1] = tmp[i][1];
		s[next[index]][2] = tmp[i][2];
		next[index]++;
	}
	return first;
}

int main()
{
  int n;
	int i,j;
	char ft[100][3] = {0};
	char S[100];
	char S1[100];
	char C = ' ';
	char tmp = ' ';
	char lastc = ' ' ;
	int first;
	scanf("%c",&C);
	if(C == 'A')
	{
		scanf("%d",&n);
		scanf("%s",&S);
		for(i=0;i<n;i++)
		{	
			ft[i][0] = S[0];
			ft[i][1] = S[n-1];
			for(j=0;j<n-1;j++)
				S[j] = S[j+1];
			S[n-1] = ft[i][0];
		}
		first = bucketsort(ft,n);
		for(i=0;i<n;i++)
		{
			S1[i] = ft[i][1];	
		}
		S1[n]='\0';
		printf("%s\n",S1);
		printf("%d\n",first);
	}
	else if(C =='B')
	{
		scanf("%d",&n);
		scanf("%s",&S1);
		scanf("%d",&first);
		tmp = S1[first-1];

		for(i=0;i<n;i++)
		{
			S[i] = S1[i];
			ft[i][0] = S1[i];
			ft[i][1] = S1[i];
		}
		S[n] = '\0';
		bucketsort(ft,n);
		for(i=0;i<n;i++)
		{
			ft[i][1] = S1[i];
			ft[i][2] = '0';
		}
		for(i=0;i<n;i++)
		{
			if(ft[i][0] == tmp)
			{
				first = i;
				break;
			}
		}
		lastc = ft[first][1];
		ft[first][2] = '1';
		S[n-1] = ft[first][1];
		for(i=1;i<n;i++)
			for(j=n-1;j>=0;j--)
				if(ft[j][0] == lastc && ft[j][2] == '0')
				{
					lastc = ft[j][1];
					ft[j][2] = '1';
					S[n-1-i] = ft[j][1];
					break;
				}
		printf("%s\n",S);
	}
  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