POJ1132

来源:互联网 发布:程序员公众号 编辑:程序博客网 时间:2024/05/17 21:46

*题目大意*:

有一个封闭路径, 打印边缘。


*解题思路*:

直接模拟, 四个方向分别对应设置地图标记。

由于地图采用二维数组存储, 打印地图的时候注意需要改变坐标。

注意输入还附带一行。


*代码*:

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int map[35][35];void get_point(){    int x, y;    char str[3000];    scanf("%d%d", &x, &y);    int i;    scanf("%s", str);        for (i=0; str[i]!='.'; i++)        {            switch(str[i])            {            case 'E': map[x][y-1] = 1;                      x = x+1; y = y;                      break;            case 'N': map[x][y] = 1;                      x = x; y = y+1;                      break;            case 'W': map[x-1][y] = 1;                      x = x-1; y = y;                      break;            case 'S': map[x-1][y-1] = 1;                      x = x; y = y-1;                      break;            }        }}int main(){  //  freopen("1.txt", "r", stdin);    int t;    scanf("%d", &t);    int n = t;    while (t--)    {        memset(map, 0, sizeof(map));        get_point();        printf("Bitmap #%d\n", n-t);        int i, j;        for (i=0; i<32; i++)        {            for (j=0; j<32; j++)            {                if (map[j][31-i]) printf("X");                else printf(".");            }            putchar('\n');        }        putchar('\n');    }    return 0;}


0 0