Border


1649.    Border
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 655    Accepted Runs: 285



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 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

1
2 1
EENNWNENWWWSSSES.

Sample Output

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



题意概述:没什么可说的,对照着图看一下就什么都明白了。

解题思路:本题是一个找规律的题目,只需要找出四种情况下的不同规律就可以了。值得注意的是,此题需要用到一个二维字符数组,而在人的印象中数组是从左上角到右下角的,即左上角为[0][0],右下角为[n][n],这在本题中就需要一个转换,转换也很简单,只要规律找到了,一切都好说。直接看源代码吧。

规律如下:

                           X                   Y                                 行                                            列  
           E             2                     1                                 31 =32-Y                                2=X
           E             3                     1                                 31=32-Y                                 3=X      每次向右移动X要加1

          W            4                      3                                 31=31-Y                                 3=X-1
           W            4                      5                                 31=31-Y                                 3=X-1  每次向西移动X要减1

          S             1                      5                                 27=32-Y                                 0=X-1
          S             1                      3                                 29=32-Y                                 0=X-1 每次向南移动Y要减去1

         N            4                      1                                  30=31-Y                                 4=X
         N            4                      4                                  27=31-Y                                 4=X    每次向北移动Y要加1


源代码:

#include<iostream>
using namespace std;


int main()
{
    int N,X,Y;
    char F,Array[32][32];
    cin>>N;
    for(int i=1;i<=N;++i)
    {
         for(int j=0;j<32;++j)
              for(int k=0;k<32;++k)
                   Array[j][k]='.';
         cin>>X>>Y;
         while(cin>>F&&F!='.')
         {
              if(F=='E'){
                         Array[32-Y][X]='X';
                         ++X;
              }      
              else if(F=='W'){
                         Array[31-Y][X-1]='X';
                         --X;
              }              
              else if(F=='S'){
                         Array[32-Y][X-1]='X';
                         --Y;
              }
              else if(F=='N'){
                         Array[31-Y][X]='X';
                         ++Y;
              }
         }
         cout<<"Bitmap #"<<i<<endl;
         for(int j=0;j<32;++j)
         {
              for(int k=0;k<32;++k)
                   cout<<Array[j][k];
              cout<<endl;
         }
         cout<<endl;
    }
    return 0;
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值