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 一会儿是AC呢,害得我找错误半天.

Posted by fql5188 at 2008-07-16 01:47:17 on Problem 1159
runtime error代码(原封不动的copy过来了):
#include<stdio.h>
char ch[5001];
short min[5000][5000]={0};
int minnum(short a,short b)
{
	return a>b?b:a;
}
int main()
{
	short n;
	short i,j,k;
	scanf("%d",&n);
	scanf("%s",ch);
    for(i=n-1;i>=0;i--)
		for(j=i;j<n;j++)
		{
			if(ch[i]==ch[j])
               min[i][j]=min[i+1][j-1];
			else
				min[i][j]=1+minnum(min[i+1][j],min[i][j-1]);
		}
		printf("%d\n",min[0][n-1]);
		return 0;
}
这是哪份AC的代码:
#include<stdio.h>
char ch[5001];
short min[5000][5000]={0};
int minnum(short a,short b)
{
	return a>b?b:a;
}
int main()
{
	short n;
	short i,j,k;
	scanf("%d",&n);
	scanf("%s",ch);
    for(i=n-1;i>=0;i--)
		for(j=i+1;j<n;j++)
		{
			if(ch[i]==ch[j])
               min[i][j]=min[i+1][j-1];
			else
				min[i][j]=1+minnum(min[i+1][j],min[i][j-1]);
		}
		printf("%d\n",min[0][n-1]);
		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