Follows 10336.c (Total 88 lines):

/* @JUDGE_ID:4461XX 10336 C "dfs" */
/* A */

#include<stdio.h>
#include<stdlib.h>
#define MAX 26

struct DATA{
	char ch ;
	int val ;
} ;
struct DATA howMuch[MAX] ;

int row , col ;
char *map ;

void erase( int i , int j )
{
	char tmp=map[i*col+j] ;

	map[i*col+j] = 0 ;
	if( i+1<row )
		if( map[(i+1)*col+j]==tmp ) erase( i+1 , j ) ;
	if( i-1>=0 )
		if( map[(i-1)*col+j]==tmp ) erase( i-1 , j ) ;
	if( j+1<col ) 
		if( map[i*col+(j+1)]==tmp ) erase( i , j+1 ) ;
	if( j-1>=0 )
		if( map[i*col+(j-1)]==tmp ) erase( i , j-1 ) ;
}
void print( void )
{
	int i , j ;

	for( i=0 ; i<MAX ; ++i ) /*sort*/
		for( j=i+1  ; j<MAX ; ++j )
			if( howMuch[i].val<howMuch[j].val ){
				howMuch[i].val ^= howMuch[j].val ^= howMuch[i].val ^= howMuch[j].val ;
				howMuch[i].ch ^= howMuch[j].ch ^= howMuch[i].ch ^= howMuch[j].ch ;
			}
	for( i=0 ; i<MAX ; ++i )
		if( howMuch[i].val )
			printf( "%c: %d\n" , howMuch[i].ch , howMuch[i].val ) ;
}
void init( void )
{
	int i ;

	for( i=0 ; i<MAX ; ++i ){
		howMuch[i].ch = i+'a' ;
		howMuch[i].val = 0 ;
	}
}
void toDo( void )
{
	int i , j ;
	
	scanf( "%d %d\n" , &row , &col ) ;
	map = (char *)malloc( sizeof( char )*col*row ) ;

	init() ;
	
	for( i=0 ; i<row ; ++i,scanf( "\n" ) )
		for( j=0 ; j<col ; ++j )
			scanf( "%c" , map+i*col+j ) ;

	for( i=0 ; i<row ; ++i )
		for( j=0 ; j<col ; ++j )
			if( map[i*col+j] ){
				++howMuch[ map[i*col+j]-'a' ].val ;
				erase( i , j ) ;
			}

	print() ;
	free( map ) ;
}
int main( void )
{
	int cases , i ;

	scanf( "%d" , &cases ) ;
	for( i=1 ; i<=cases ; ++i ){
		printf( "World #%d\n" , i ) ;
		toDo() ;
	}

	return 0 ;
}

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