Follows 446.c (Total 59 lines):

/* @JUDGE_ID:4461XX 446 C */
/* A */
#include<math.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
char arr[2][5] ;
void analysis( void )
{
	int i , j ;
	for( i=0 ; i<2 ; i++ )
		for( j=0 ; arr[i][j] ; j++ )
			if( isdigit( arr[i][j] ) ) arr[i][j] -= '0' ;
			else arr[i][j] -= 'A' - 10 ;
}
int count( int k , int len )
{
	int sum=0 , i , j ;
	for( i=len-1 , j=0 ; j<len ; i-- , j++ )
		sum += arr[k][j] * (int)pow( 16 , i ) ;
	return sum ;
}
void Turn2( int num )
{
	int i ;
	for( i=12 ; i>=0 ; i-- )
		if( num >= (int)pow( 2 , i ) ){
			putchar( '1' ) ;
			num -= (int)pow( 2 , i ) ;
		}
		else putchar( '0' ) ;
}
void input( void )
{
	int len[2] , num[2] ; /* num in base 10 */
	char ch ;
	scanf( "%s %c %s\n" , arr[0] , &ch , arr[1] ) ;

	len[0] = strlen( arr[0] ) ;
	len[1] = strlen( arr[1] ) ;
	analysis() ;
	num[0] = count( 0 , len[0] ) ;
	num[1] = count( 1 , len[1] ) ;

	Turn2( num[0] ) ;
	printf( " %c " , ch ) ;
	Turn2( num[1] ) ;

	if( ch == '+' ) printf( " = %d\n" , num[0]+num[1] ) ;
	else printf( " = %d\n" , num[0]-num[1] ) ;
}
void main( void )
{
	int N , num ;
/*	freopen( "C:\\windows\\desktop\\446.in" , "r" , stdin ) ;*/
	scanf( "%d" , &N ) ;
	for( ; N ; N-- ) input() ;
}
/* @END_OF_SOURCE_CODE */

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