Follows 110.c (Total 99 lines):

/* @JUDGE_ID:4461XX 110 C "Recursion" */
/* A */
#include<stdio.h>

char data[8] , data_tmp[8][8] ;
void initial( int n )
{
	int i ;

	for( i=0 ; i<n ; i++ ) data[i] = 'a' + i ;

	puts( "program sort(input,output);" ) ;
	puts( "var" ) ;
	for( i=0 ; i<n ; i++ ){
		if( i ) putchar( ',' ) ;
		putchar( data[i] ) ;
	}
	puts( " : integer;" ) ;
	puts( "begin" ) ;
	printf( "  readln(" ) ;
	for( i=0 ; i<n ; i++ ){
		if( i ) putchar( ',' ) ;
		putchar( data[i] ) ;
	}
	puts( ");" ) ;
}
void end( void )
{
	puts( "end." ) ;
}
void pritab( int level )
{
	int j ;
	
	for( j=0 ; j<2*level ; j++ ) putchar( ' ' ) ;
}
void print( int n )
{
	int i ;
	
	pritab( n ) ;
	printf( "writeln(" ) ;
	for( i=0 ; i<n ; i++ ){
		if( i ) putchar( ',' ) ;
		putchar( data[i] ) ;
	}
	puts( ")" ) ;
}
void swap( int a , int b )
{
	int tmp ;

	tmp = data[a] ;
	data[a] = data[b] ;
	data[b] = tmp ;
}
void recursive( int level , int n )
{
	int i ;
	
	if( level==n ) print( n ) ;
	else{
		for( i=0 ; i<n ; i++ ) data_tmp[level-1][i] = data[i] ;
		for( i=level ; i>=0 ; i-- ){
			pritab( level ) ;
			if( i ){
				if( i!=level ) printf( "else " ) ;
				printf( "if %c < %c then\n" , data[i-1] , data[i] ) ;
			}
			else
				puts( "else" ) ;
			recursive( level+1 , n ) ;
			
			if( i>0 ) swap( i-1 , i ) ;
		}
		for( i=0 ; i<n ; i++ ) data[i] = data_tmp[level-1][i] ;
	}
}
int main( void )
{
	int casetime , n ;
	
	/*freopen( "out" , "w" , stdout ) ;*/

	scanf( "%d" , &casetime ) ;
	for( ; casetime ; casetime-- ){
		scanf( "%d" , &n ) ;
		
		initial( n ) ;
		recursive( 1 , n ) ;
		end() ;

		if( casetime-1>0 )
			putchar( '\n' );
	}
	
	return 0 ;
}
/* @END_OF_SOURCE_CODE */

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