Description

American Carnival Makers Inc. (ACM) has a long history of designing rides and attractions. One of their more popular attractions is a fun house that includes a room of mirrors. Their trademark is to set up the room so that when looking forward from the entry
door, the exit door appears to be directly ahead. However, the room has double-sided mirrors placed throughout at 45 degree angles. So, the exit door can be on any of the walls of the room. The set designer always places the entry and mirrors, but can never
seem to be bothered to place the exit door. One of your jobs as part of the construction crew is to determine the placement of the exit door for the room given an original design.

The final diagram for a sample room is given below. The asterisk (*) marks the entry way, lower case x's mark the walls, the mirrors are given by the forward and backward slash characters (/ and \), open spaces with no visual obstructions are marked by periods
(.), and the desired placement of the exit is marked with an ampersand (&). In the input diagram, there is an 'x' in place of the '&', since the exit has not yet been located. You need to alter the input diagram by replacing the proper 'x' with an '&' to identify
the exit. Note that entrances and exits can appear on any of the walls (although never a corner), and that it is physically impossible for the exit to be the same as the entrance. (You don't need to understand why this is so, although it may be fun to think
about.)

xxxxxxxxxxx

x../..\...x

x..../....x

*../......x

x.........x

xxxxxx&xxxx

Input

Each room will be preceded by two integers, W and L, where 5 ≤ W ≤ 20 is the width of the room including the border walls and 5 ≤ L ≤ 20 is the length of the room including the border walls. Following the specification of W and L are L additional lines containing
the room diagram, with each line having W characters from the alphabet: { * , x , . , / , \ }. The perimeter will always be comprised of walls, except for one asterisk (*) which marks the entrance; the exit is not (yet) marked. A line with two zeros indicates
the end of input data.

Output

For each test case, the first line will contain the word, HOUSE, followed by a space and then an integer that identifies the given fun house sequentially. Following that should be a room diagram which includes the proper placement of the exit door, as marked
by an ampersand (&).

Sample Input

11 6
xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxxxxxxx
5 5
xxxxx
*...x
x...x
x...x
xxxxx
5 5
xxxxx
x./\x
*./.x
x..\x
xxxxx
6 6
xxx*xx
x/...x
x....x
x/./.x
x\./.x
xxxxxx
10 10
xxxxxxxxxx
x.../\...x
x........x
x........x
x.../\..\x
*...\/../x
x........x
x........x
x...\/...x
xxxxxxxxxx
0 0

Sample Output

HOUSE 1
xxxxxxxxxxx
x../..\...x
x..../....x
*../......x
x.........x
xxxxxx&xxxx
HOUSE 2
xxxxx
*...&
x...x
x...x
xxxxx
HOUSE 3
xxxxx
x./\x
*./.x
x..\&
xxxxx
HOUSE 4
xxx*xx
x/...x
x....x
x/./.&
x\./.x
xxxxxx
HOUSE 5
xxxxxxxxxx
x.../\...x
x........x
x........x
&.../\..\x
*...\/../x
x........x
x........x
x...\/...x
xxxxxxxxxx
超时超了10多次,把scanf改成cin就AC了。。。因为一个字符一个字符输入,可能最后会有多个空格,这样就错了,所有尽量改成scanf("%s",str);这样也能过的
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
char str[100][100];
int tab[100][100][3];
int main()
{
    int n,m,i,j,x,y,h=0,a,b;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0 && m==0)
        break;
        getchar();
        h++;
        memset(str,0,sizeof(str));
        memset(tab,0,sizeof(tab));
        for(i=1;i<=m;i++)
        {
            for(j=1;j<=n;j++)
            {
                cin>>str[j][i];
                if(str[j][i]=='*')
                {
                    x=j;
                    y=i;
                }
            }
            //if(i!=m)
            //getchar();
        }
        if(x==1)
        {
          tab[x][y][0]=1;
          tab[x][y][1]=0;
        }
        else if(y==1)
        {
            tab[x][y][0]=0;
            tab[x][y][1]=1;
        }
        else if(y==m)
        {
            tab[x][y][0]=0;
            tab[x][y][1]=-1;
        }
        else if(x==n)
        {
            tab[x][y][0]=-1;
            tab[x][y][1]=0;
        }
         
        while(1)
        {
            a=tab[x][y][0];
            b=tab[x][y][1];
            x=x+a;
            y=y+b;
            tab[x][y][0]=a;
            tab[x][y][1]=b;
            if(str[x][y]=='x')
            {
                str[x][y]='&';
                break;
            }
            if(str[x][y]=='.')
            continue;
            if(str[x][y]=='/')
            {
                if(tab[x][y][0]==0)
                {
                    if(tab[x][y][1]==1)
                    {
                        tab[x][y][0]=-1;
                        tab[x][y][1]=0;
                    }
                    else
                    {
                        tab[x][y][0]=1;
                        tab[x][y][1]=0;
                    }
                }
                else if(tab[x][y][1]==0)
                {
                    if(tab[x][y][0]==1)
                    {
                        tab[x][y][0]=0;
                        tab[x][y][1]=-1;
                    }
                    else if(tab[x][y][0]==-1)
                    {
                        tab[x][y][0]=0;
                        tab[x][y][1]=1;
                    }
                }
            }
             
            if(str[x][y]=='\\')
            {
                if(tab[x][y][0]==0)
                {
                    if(tab[x][y][1]==1)
                    {
                        tab[x][y][0]=1;
                        tab[x][y][1]=0;
                    }
                    else if(tab[x][y][1]==-1)
                    {
                        tab[x][y][0]=-1;
                        tab[x][y][1]=0;
                    }
                }
                else if(tab[x][y][1]==0)
                {
                    if(tab[x][y][0]==1)
                    {
                        tab[x][y][0]=0;
                        tab[x][y][1]=1;
                    }
                    else
                    {
                        tab[x][y][0]=0;
                        tab[x][y][1]=-1;
                    }
                }
            }
             
        }
        printf("HOUSE %d\n",h);
        for(i=1;i<=m;i++)
        {
            for(j=1;j<=n;j++)
            printf("%c",str[j][i]);
            printf("\n");
        }
    }
     
}
 

最新文章

  1. WebStorm文件类型关联设置
  2. linux软raid练习
  3. 5. Singleton(单例)
  4. easyui datagrid中关联combox
  5. NFS 网络文件系统挂载在A8板子上
  6. mac攻略(一) -- git使用
  7. WebApi:使用方法名或者控制器名作为接口地址
  8. Android API 中文 ListView
  9. ios 从微信返回自己的app
  10. 瑕疵(bug)严重性定义
  11. react-native学习笔记——简单尝试
  12. Javascript数组的声明
  13. No.2小白的HTML+CSS心得篇
  14. FxZ,C#开发职位面试测试题(30分钟内必须完成)
  15. ::在c++中什么意思
  16. vue组件详解(二)——使用props传递数据
  17. vue and jest测试
  18. 通过DFS求解有向图(邻接表存储)中所有简单回路
  19. [转帖]AMOLED的技术和OLED有哪些联系和区别
  20. Get shell By Powershell

热门文章

  1. LeetCode430 扁平化多级双向链表
  2. Flutter 应用入门:包管理
  3. iTerm2 实现 ssh 自动登录,并使用 Zmodem 实现快速传输文件
  4. 【System】I/O密集型和CPU密集型工作负载之间有什么区别
  5. 【Linux】salt的cmd.script命令介绍
  6. ctfhub技能树—sql注入—整数型注入
  7. Java开发工具类集合
  8. Sentry(v20.12.1) K8S 云原生架构探索,JavaScript Enriching Events(丰富事件信息)
  9. k8s-jenkins持续发布tomcat项目
  10. java实现Excel定制导出(基于POI的工具类)