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

Re:为什么总是RE?高手帮我看一下

Posted by snake19851124 at 2007-11-16 11:15:56 on Problem 1159
In Reply To:为什么总是RE?高手帮我看一下 Posted by:RiverM at 2007-11-16 11:09:13
Your program is to read from standard input. The first line contains one integer: the length of the input string N, 3 <= N <= 5000. 
> #include<stdio.h>
> #define M 101       // 这个有问题吧
> #define N 101       // 这个有问题吧
> int cmp(char ch1[],char ch2[])
> {
> 	int len1=0,len2=0,temp=0,min=0;
> 	int a[M][N],i=0,j=0;
> 	while(ch1[len1]!='\0')
>       len1++;
> 	while(ch2[len2]!='\0')
>       len2++;
> 	for(i=0;i<=len1;i++)a[i][0]=i;
> 	for(j=0;j<=len2;j++)a[0][j]=j;
> 	for(i=1;i<=len1;i++)
> 		for(j=1;j<=len2;j++)
> 		{
> 			min=32767;
> 			temp=ch1[i-1]==ch2[j-1] ? 0:2;
> 			if(min>a[i-1][j]+1)
> 				min=a[i-1][j]+1;
> 			if(min>a[i][j-1]+1)
> 				min=a[i][j-1]+1;
>          	if(min>a[i-1][j-1]+temp)
> 				min=a[i-1][j-1]+temp;
> 			a[i][j]=min;
> 		}
> 		return a[len1][len2];
> }
> int depart(char ch[],int len)
> {
> 	int i=0,j=0,k=0,min=32767,rem1=0,rem2=0,temp=0;
> 	char ch1[M],ch2[N];
> 	min=len;
> 	for(i=0;i<len;i++)
> 	{
> 		for(j=0;j<M;j++) ch1[j]='\0';
>         for(j=0;j<N;j++) ch2[j]='\0';
> 		for(j=0;j<i;j++)
> 		{
> 			ch1[j]=ch[j];
> 		}
> 		ch1[j+1]='\0';
> 		temp=len-j-1;
> 		ch2[temp+1]='\0';
> 		for(j,k=len-j-1;j<len;j++,k--)
> 		{
> 			ch2[k]=ch[j];
> 		}
> 	
> 		rem1=cmp(ch1,ch2);
> 		ch2[temp]='\0';
> 		rem2=cmp(ch1,ch2);
> 		if(min>rem1)
> 			min=rem1;
>         if(min>rem2)
> 			min=rem2;
> 	}
> 	return min;
> }
> int main()
> {
> 	int len;
> 	scanf("%d",&len);
> 	char ch[N];
> 
> 	scanf("%s",ch);
> 	
> 	printf("%d",depart(ch,len));
> 	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