Follows 120.c (Total 41 lines):

/* @JUDGE_ID:4461XX 120 C */
/* A */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int pancake[30] ;
int sort_function( const void *a , const void *b )
{
	return *( int * )a - *( int * )b ;
}
void turn( int tail )
{
	int star , temp ;
	for( star=0 ; tail>star ; star++ , tail-- ){
		temp = pancake[star] ;
		pancake[star] = pancake[tail] ;
		pancake[tail] = temp ;
	}
}
void main( void )
{
	int sorted[30] , num , i , j ;
	char arr[4000] , *p ;
	while( gets( arr ) ){
		puts( arr ) ;
		for( p=strtok( arr , " " ) , num=0 ; p ; p=strtok( NULL , " " ) , num++ )
			sorted[num] = pancake[num] = atoi( p ) ;
		qsort( ( void * )sorted , num , sizeof( int ) , sort_function ) ;
		for( i=num-1 ; i ; i-- )
			if( pancake[i] != sorted[i] ){
				for( j=i-1 ; j ; j-- )
					if( pancake[j] == sorted[i] ){
						turn( j ) ;
						printf( "%d " , num-j ) ;
					}
				turn( i ) ;
				printf( "%d " , num-i ) ;
			}
		printf( "0\n" ) ;
	}
}

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