Follows 332.c (Total 63 lines):

/* @JUDGE_ID:4461XX 332 C */
/* A */
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long den/*denominator*/ , num/*numerator*/ ;
char arr_den[15], arr_num[15] ;
int input( void )
{
	int i ;
	char *tmp ;
	scanf( "%s" , arr_num ) ;
	strtok( arr_num ,"." ) ;
	tmp = strtok( NULL ,"." ) ;
	strcpy( arr_num , tmp ) ;
	return strlen( arr_num ) ;
}
void make_den( int len , int digit )
{
	int i , tail=-1 ;
	if( !digit ) arr_den[++tail] = '1' ;
	for( i=0 ; i<digit ; i++ ) arr_den[++tail] = '9' ;
	for( i=0 ; i<len-digit ; i++ ) arr_den[++tail] = '0' ;
	arr_den[++tail] = NULL ;
	den = atol( arr_den ) ;
}
void make_num( int len , int digit )
{
	long a , b ;
	a = atol( arr_num ) ;
	arr_num[len-digit] = NULL ;
	b = atol( arr_num ) ;
	if( !digit ) b = 0 ;
	num = a - b ;
}
void count( void )
{
	long i , den1=den , num1=num , tmp ;
	while( num1 ){
		den1 %= num1 ;
		tmp = den1 ;
		den1 = num1 ;
		num1 = tmp ;
	}
	den /= den1 ;
	num /= den1 ;
}
void main( void )
{
	int digit , time , len ;
	for( time=1 ; ; time++ ){
		scanf( "%d" , &digit ) ;
		if( digit==-1 ) break ;
		len = input() ;
		make_den( len , digit ) ;
		make_num( len , digit ) ;
		count() ;
		printf( "Case %d: %ld/%ld\n" , time , num , den ) ;

	}
}
/* @END_OF_SOURCE_CODE */

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