⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2512.txt

📁 北大ACM题目例程 详细的解答过程 程序实现 算法分析
💻 TXT
字号:

#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("faint\n");
	}
	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( "%d\n", ans );

	}
	return 0;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -