http://poj.org/problem?id=2512
#include <stdio.h>
int dx[]={ 0, 0, 1,-1, 1, 1,-1,-1, 1, 1, 2, 2,-1,-1,-2,-2 };
int dy[]={-1, 1, 0, 0, 1,-1, 1,-1, -2, 2,-1, 1,-2, 2,-1, 1 };
char map[8][9];
#define true '.'
#define false 'x'
inline bool inmap( int x, int y )
{
return 0<=x && x<8 && 0<=y && y<8;
}
void doit( char c, int x, int y )
{
int i, j, xx, yy;
map[x][y] = 'o';
switch( c )
{
case 'k':case 'K':
for( i=0; i<8; i++ )
{
if( inmap( xx=x+dx[i], yy=y+dy[i] ) )
if( map[xx][yy] == true )
map[xx][yy] = false;
}
break;
case 'q': case'Q':
for( i=0; i<8; i++ )
for( j=1; j<8; j++ )
{
if( !inmap( xx=x+dx[i]*j, yy=y+dy[i]*j ) || map[xx][yy] == 'o' )
break;
if( map[xx][yy] == true )
map[xx][yy] = false;
}
break;
case 'r': case'R':
for( i=0; i<4; i++ )
for( j=1; j<8; j++ )
{
if( !inmap( xx=x+dx[i]*j, yy=y+dy[i]*j ) || map[xx][yy] == 'o' )
break;
if( map[xx][yy] == true )
map[xx][yy] = false;
}
break;
case 'b': case'B':
for( i=4; i<8; i++ )
for( j=1; j<8; j++ )
{
if( !inmap( xx=x+dx[i]*j, yy=y+dy[i]*j ) || map[xx][yy] == 'o' )
break;
if( map[xx][yy] == true )
map[xx][yy] = false;
}
break;
case 'n': case'N':
for( i=8; i<16; i++ )
{
if( inmap( xx=x+dx[i], yy=y+dy[i] ) )
if( map[xx][yy] == true )
map[xx][yy] = false;
}
break;
case 'p':
for( i=4; i<6; i++ )
{
if( inmap( xx=x+dx[i], yy=y+dy[i] ) )
if( map[xx][yy] == true )
map[xx][yy] = false;
}
break;
case 'P':
for( i=6; i<8; i++ )
{
if( inmap( xx=x+dx[i], yy=y+dy[i] ) )
if( map[xx][yy] == true )
map[xx][yy] = false;
}
break;
default: while(1)printf("faintn");
}
return;
}
int main()
{
int xt[64],yt[64],s;
int i, j, x, y;
char c,ct[64];
while( 1 )
{
x=0, y=0;
for( i=0; i<8; i++ )
for( j=0; j<8; j++ )
map[i][j] = true;
s = 0;
while( 1 )
{
if( scanf("%c",&c ) != 1 )return 0;
if( c >= '0' && c <= '9' ) y += c-'0';
else if( c == '/' ) x++,y=0;
else if( c =='n' ) break;
else
{
xt[s] = x;
yt[s] = y;
ct[s] = c;
map[x][y] = 'o';
s++;
y++;
}
}
while( s-- )
doit( ct[s], xt[s], yt[s] );
int ans;
ans = 0;
for( i=0; i<8; i++ )
for( j=0; j<8; j++ )
if( map[i][j] == true ) ans ++;
printf( "%dn", ans );
}
return 0;
}