Follows 417.c (Total 69 lines):

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

#define MAX 83681

char data[MAX][5+1] ;

void make_data( int length , int level )
{
	static int num=0 ;
	static char ans[5+1] ;

	int i ;

	if( length==level ){
		ans[length] = 0 ;
		strcpy( data[num++] , ans ) ;
	}
	else{
		if( level==0 ) i=0 ;
		else i=ans[level-1]-'a'+1 ;

		for( ; i<26 ; ++i ){
			ans[level] = i+'a' ;
			make_data( length , level+1 ) ;
		}
	}
}
void prepare( void )
{
	int length ;

	for( length=1 ; length<=5 ; ++length ) make_data( length , 0 ) ;
}
int My_Search( char *str )
{
	int i ;

	for( i=0 ; i<MAX ; ++i )
		if( !strcmp( str , data[i] ) ) return i+1 ;
	
	return -1 ;
}
void ToRun( void )
{
	char in_tmp[5+1] ;
	int i , ok ;

	while( gets( in_tmp ) ){
		for( i=1,ok=1 ; i<strlen( in_tmp ) ; ++i )
			if( in_tmp[i]<=in_tmp[i-1] ){
				ok = 0 ;
				break ;
			}

		if( ok ) ok = My_Search( in_tmp ) ;

		printf( "%d\n" , ok ) ;
	}
}
int main( void )
{
	prepare() ; /* make data[][] */
	ToRun() ;

	return 0 ;
}

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