poj1132 简单模拟

来源:互联网 发布:红蜘蛛端口号怎么修改 编辑:程序博客网 时间:2024/06/07 07:44


Border
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3842 Accepted: 1813

Description

You are to write a program that draws a border around a closed path into a bitmap, as displayed in the following figure: 

The path is closed and runs along the grid lines, i.e. between the squares of the grid. The path runs counter-clockwise, so if following the path is considered as going ``forward'', the border pixels are always to the "right'' of the path. The bitmap always covers 32 by 32 squares and has its lower left corner at (0, 0). You can safely assume that the path never touches the bounding rectangle of the bitmap and never touches or crosses itself. Note that a bit gets set if it is on the outside of the area surrounded by the path and if at least one of its edges belongs to the path, but not if only one of its corners is in the path. (A look at the convex corners in the figure should clarify that statement.) 

Input

The first line of the input file contains the number of test cases in the file. Each test case that follows consists of two lines. The first line of each case contains two integer numbers x and y specifying the starting point of the path. The second line contains a string of variable length. Every letter in the string symbolizes a move of length one along the grid. Only the letters 'W' ("west"), 'E' ("east"), 'N' ("north"), 'S' ("south"), and '.' ("end of path", no move) appear in the string. The end-of-path character ( '.') is immediately followed by the end of the line.

Output

For each test case, output a line with the number of the case ('Bitmap #1', 'Bitmap #2', etc.). For each row of the bitmap from top to bottom, print a line where you print a character for every bit in that row from left to right. Print an uppercase 'X' for set bits and a period '.' for unset bits. Output a blank line after each bitmap.

Sample Input

12 1EENNWNENWWWSSSES.

Sample Output

Bitmap #1.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................XXX............................X...X...........................X..X............................X...X............................X..X.............................XX............................




题意清楚,没有昨天的题目那么难懂:就是从某一点出发,按照题目给的指令进行,然后在他走的右边进行标记,把标记的打印出来就好了





#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int main(){    int T;    int x,y;    char str[1000];    scanf("%d",&T);    char ans[40][40];    int coun=1;    while(T--)    {        for(int i=0;i<=33;i++)            for(int j=0;j<=33;j++)                ans[i][j]='.';        scanf("%d%d",&x,&y);        scanf("%s",str);        printf("Bitmap #%d\n",coun++);        for(int i=0;str[i]!='.';i++){            if(str[i]=='E'){                x++;                ans[y-1][x-1]='X';            }            else if(str[i]=='S'){                y--;                ans[y][x-1]='X';            }            else if(str[i]=='W'){                x--;                ans[y][x]='X';            }            else{                y++;                ans[y-1][x]='X';            }        }        for(int i=31;i>=0;i--){            for(int j=0;j<32;j++)                printf("%c",ans[i][j]);            puts("");        }        if(T)            puts("");    }    return 0;}


0 0
原创粉丝点击