【FOJ】Problem 1428 Border

Problem 1428 Border.

题意

  • 画出路径边界(32x32)
    逆时针运行的,如果跟随路径被视为“前进”,则边界像素始终位于路径的“右侧”。
    即:E-像素块在下,N-像素块在右,W-像素块在上,S-像素块在左
  • 输入:
    测试用例数n
    路径的启示地址x,y
    ‘W’ (“west”), ‘E’ (“east”), ‘N’ (“north”), ‘S’ (“south”), and ‘.’ (“end of path”, no move)
  • 输出:
    Bitmap #1
    然后图
    每组数据间一个空行

思路

  • 看图操作:
    E-下面的像素块标X,坐标右移=数组列向量+1
    N-本坐标像素块标X,坐标上移=数组行向量+1
    W-左侧的像素块标X,坐标左移=数组列向量-1
    S-坐标下移=数组行向量-1,左侧的像素块标X

代码

#include<cstdio>
#include<string.h>
using namespace std;

char a[32][32];

void change(int &i, int &j, char tag){
	switch(tag){
		case 'E':
			a[i-1][j++] = 'X';
			break;
		case 'N':
			a[i++][j] = 'X';
			break;
		case 'W':
			a[i][--j] = 'X';
			break;
		case 'S':
			a[--i][j-1] = 'X';
			break;
	}
}

int main(){
	int n;
	int i, j;
	char op;
	scanf("%d", &n);
	for(int k=1; k<=n; k++){
		memset(a, '.', sizeof(a));
		scanf("%d%d", &j, &i);	//横坐标是数组的列向量,纵坐标是数组的行向量
		scanf("%c", &op);
		while(op!='.'){
			change(i, j, op);
			scanf("%c", &op);
		}
		getchar();
		printf("Bitmap #%d\n", k);
		for(i=31; i>=0; i--){
			for(j=0; j<32; j++)
				printf("%c", a[i][j]);
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}
发布了46 篇原创文章 · 获赞 0 · 访问量 461

猜你喜欢

转载自blog.csdn.net/qq_44531167/article/details/105474265