中易网

C/C++编程题3

答案:1  悬赏:30  
解决时间 2021-04-28 15:00

here is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.

Write a program to count the number of black tiles which he can reach by repeating the moves described above.

Input Format: (c3.in)

The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.

There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.

· '.' - a black tile

· '#' - a red tile

· '@' - a man on a black tile(appears exactly once in a data set)

The end of the input is indicated by a line consisting of two zeros.

Output Format: (c3.out)

For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).

Sample Input:

6 9

....#.

.....#

......

......

......

......

......

#@...#

.#..#.

11 9

.#.........

.#.#######.

.#.#.....#.

.#.#.###.#.

.#.#..@#.#.

.#.#####.#.

.#.......#.

.#########.

...........

11 6

..#..#..#..

..#..#..#..

..#..#..###

..#..#..#@.

..#..#..#..

..#..#..#..

7 7

..#.#..

..#.#..

###.###

...@...

###.###

..#.#..

..#.#..

0 0

Sample Output:

45

59

6

13

这是提问,希望高手们帮忙写下,请讲代码发送到zmqoal@vip.qq.com,回复时说已经发送,我好给分!由于计算相似度,请各位高手们帮忙自己写下,谢谢了~高分悬赏!

最佳答案

已将答案发到你邮箱


注意查收

我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
未来没有目标,人活着还有什么意义吗
我姓明却…………后面接一句句子
双方离婚时候可以把财产全部给孩子吗?
轩辕剑—汉之云成都飞云基地在哪里
什么电脑好???
你确定夜公园不开吗?
电脑怎么会跟着不同的颜色变暗?
QQ宠物教堂什么时候开放?
戴眼镜鼻子发麻该怎么办?
为什么我的简单百宝箱里面的软件下载不了?
来碗面(金泉街道青杠社区南)我想知道这个在什
杰伦一出新歌QQ音乐马上排行第一哪个比的了啊
2012年地球真得会毁灭吗?
烦死了,WOW;练级问题
重国有几个叫钱泽浩的
推荐资讯
善待自己的标准是什么?
能不能教我制作DNF技能补丁
谁给我做下这个个网名?
DNF湖北三区幽灵法杖收多少钱
QQ個性分組
机械功率计算公式
因式分解:x^2+2x+1
天龙八部这游戏怎么样
她还喜欢我吗!!1
沉默表示什么?
显卡接口问题
为什么we169网站打不开
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?