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

数组大小一定要注意,苦逼的过了几遍,最后居然是数组太小.....

Posted by 20122430139 at 2014-03-17 14:57:05 on Problem 1458
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1001   //刚开始是100,就错了
#define  Max(x,y)  (x)>(y)?(x):(y)
int main()
{
	char string1[MAX];
	char string2[MAX];
	//char string1a[26];
	//char string1b[26];
	int string[MAX][MAX];
	int max1,max2,i,j;
	
	while(scanf("%s%s",string1,string2)!=EOF)
	{
	memset(string, 0, sizeof(string));
	//gets(string1);
	//gets(string2);
	//memset(c,0,sizeof(string));
	max1=strlen(string1);
	max2=strlen(string2);
	
	
	for(i=1;i<=max1;i++)
	  for(j=1;j<=max2;j++)
	  {
	  	if(string1[i-1]==string2[j-1])
	  	  {
	  	  	string[i][j]=string[i-1][j-1]+1;
	  	  }
	  	else
	  	    string[i][j] = Max(string[i][j-1], string[i-1][j]);
	  }
	
	
	printf("%d\n",string[max1][max2]);
   }
	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