简单模拟题,打印逆时针闭合回路的外边框,随便写写了
#include<stdio.h>
#include<string.h>
static int getX(char c, int x)
{
if (c == 'E')
return x + 1;
else if (c == 'W')
return x - 1;
else
return x;
}
static int getY(char c, int y)
{
if (c == 'N')
return y + 1;
else if (c == 'S')
return y - 1;
else
return y;
}
int main()
{
int t, ti;
char s[32][32];
scanf("%d", &t);
for (ti = 1; ti <= t; ti++)
{
memset(s, '.', sizeof(s));
printf("Bitmap #%d\n", ti);
int px, py, nx, ny, c;
scanf("%d %d", &px, &py);
getchar();
while ((c = getchar()) != '.')
{
nx = getX(c, px);
ny = getY(c, py);
if (py == ny && px < nx)
s[px][py - 1] = 'X';
else if (px > nx)
s[nx][py] = 'X';
else if (px == nx && py < ny)
s[px][py] = 'X';
else
s[px - 1][ny] = 'X';
px = nx;
py = ny;
}
int i, j;
for (i = 31; i >= 0; i--)
{
for (j = 0; j < 32; j++)
putchar(s[j][i]);
putchar('\n');
}
putchar('\n');
}
return 0;
}