Follows 101.c (Total 74 lines):

/* @JUDGE_ID:4461XX 101 C */
/* A */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int map[25][25] , loc[25] , end[25] ;
void onto( int i )
{
	int j , test ;
	for( j=end[loc[i]] ; map[loc[i]][j]!=i ; j-- ){
		map[map[loc[i]][j]][end[map[loc[i]][j]]+1] = map[loc[i]][j] ;
		test = map[loc[i]][j] ;
		end[map[loc[i]][j]]++ ;
		map[loc[i]][j] = -1 ;
		end[loc[i]]-- ;
		loc[test] = test ;
	}
}
void move( int i , int j )
{
	map[loc[j]][end[loc[j]]+1] = i ;
	map[loc[i]][end[loc[i]]] = -1 ;
	end[loc[j]]++ ;
	end[loc[i]]-- ;
	loc[i] = loc[j] ;
}
void pile( int i , int j )
{
	int k , l , m , n , test ;
	l = loc[i] ;
	for( k=0 ; ; k++ )
		if( map[loc[i]][k] == i ) break ;
	m = end[l] - k ;
	for( k , n=0 ;  n<=m ; k++ , n++ ){
		test = map[l][k] ;
		map[loc[j]][end[loc[j]]+1] = map[l][k] ;
		map[l][k] = -1 ;
		end[loc[j]]++ ;
		end[l]-- ;
		loc[test] = loc[j] ;
	}
}
void main( void )
{
	int n , i , j , block[2] ;
	char arr[80] , ch[2] , *p ;
/*	freopen( "C:\\windows\\desktop\\101.in" , "r" , stdin ) ;*/
	scanf( "%d\n" , &n ) ;
	for( i=0 ; i<n ; i++ ){
		for( j=1 ; j<n ; j++ ) map[i][j] = -1 ;
		map[i][0] = loc[i] = i ;
		end[i] = 0 ;
	}
	while( gets( arr ) ){
		if( !strcmp( arr , "quit" ) ) break ;
		p = strtok( arr , " " ) ; ch[0] = *p ;
		p = strtok( NULL , " " ) ; block[0] = atoi( p ) ;
		p = strtok( NULL , " " ) ; ch[1] = *(p+1) ;
		p = strtok( NULL , " " ) ; block[1] = atoi( p ) ;
		if( loc[block[0]] != loc[block[1]] ){
			if( ch[1] == 'n' ) onto( block[1] ) ;
			if( ch[0] == 'm' ){
				onto( block[0] ) ;
				move( block[0] , block[1] ) ;
			}
			else pile( block[0] , block[1] ) ;
		}
	}
	for( i=0 ; i<n ; i++ ){
		printf( "%d:" , i ) ;
		for( j=0 ; j<=end[i] ; j++ ) printf( " %d" , map[i][j] ) ;
		putchar( '\n' ) ;
	}
}

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