Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么就是wrong answer附代码,是输入有问题?输出格式是对的啊。测试数据也对。#include "stdio.h" #include "stdlib.h" #include <string.h> #define MAX 450 int post[MAX]; int count = 0 ; int b[MAX][MAX]; char x[MAX][50] = {0}; char y[MAX][50] = {0}; int c[MAX][MAX] ; int temp = 0; void print(int b1[][MAX],char x1[][50],int i ,int j ); void lsc(char a[][50],char B[][50],int len_x,int len_y){ memset(c,0,sizeof(c)); int i, j; memset(c,0,sizeof(c)); for( i = 1; i <= len_x;i++) c[i][0] = 0; for( j = 0 ; j <= len_y ; j++) c[0][j] = 0; for(i = 1; i <= len_x ;i++) { for(j = 1; j <= len_y ;j++) { if(!strcmp(a[i-1] , B[j-1])) { c[i][j] = c[i-1][j-1] + 1; b[i][j] = 0; } else{ if(c[i-1][j] >= c[i][j-1]) { c[i][j] = c[i-1][j]; b[i][j] = 1; } else { c[i][j] = c[i][j-1]; b[i][j] = -1; } } } } print(b,a,len_x,len_y); } void print(int b1[][MAX],char x1[][50],int i ,int j ){ count = 0; if(i == 0 || j == 0) { return ; } if(b1[i][j] == 0 ) { print(b1,x1,i-1,j-1); post[count++] = i; } else if(b1[i][j] == 1) { print(b1,x1,i-1,j); } else if(b1[i][j] == -1) { print(b1,x1,i,j-1); } } int main(){ memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); int l1 = 1; int l2 = 1; while (scanf("%s",x[temp]) != EOF) { while(1) { if(strcmp(x[temp],"#") == 0) { break; } else{ ++temp; l1++; } scanf("%s",x[temp]); } temp = 0; while(1) { scanf("%s",y[temp]); if(strcmp(y[temp],"#") == 0) { break; } else{ ++temp; l2++; } }rewind(stdout); temp = 0; count = 0; lsc(x,y,l1-1,l2-1); l1 = 1; l2 = 1; rewind(stdout); int d = 0; for(d= 0; d < count-1; d++){ printf("%s ",x[post[d]-1]); } printf("%s\n",x[post[count-1]-1]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator