Follows 10192.c (Total 43 lines):

/* @JUDGE_ID:4461XX 10192 C "LCS" */
/* A */
#include<stdio.h>
#include<string.h>

char in[2][100+1+1] ;

int LCS( void )
{
	int table[100+1][100+1] ;
	int i , j , max ;
	
	memset( table , 0 , sizeof( table ) ) ;

	for( max=0,i=1 ; i<=strlen( &in[0][1] ) ; ++i )
		for( j=1 ; j<=strlen( &in[1][1] ) ; ++j ){
			if( in[0][i]==in[1][j] ) table[i][j] = table[i-1][j-1]+1 ;
			else table[i][j] = table[i-1][j]>table[i][j-1] ? table[i-1][j] : table[i][j-1] ;

			if( table[i][j]>max ) max = table[i][j] ;
		}

	return max ;
}
int DoInput( int time )
{
	gets( &in[0][1] ) ;
	if( !strcmp( &in[0][1] , "#" ) ) return 0 ;

	gets( &in[1][1] ) ;
	printf( "Case #%d: you can visit at most %d cities.\n" , time , LCS() ) ;
	
	return 1 ;
}
int main( void )
{
	int time ;

	for( time=1 ; DoInput( time ) ; ++time ) ;
	
	return 0 ;
}
/* @END_OF_SOURCE_CODE */

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com