中易网

C/C++编程题3

答案:1  悬赏:30  
解决时间 2021-04-28 15:00
  • 提问者网友:她是我的お女人
  • 2021-04-27 16:55

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,回复时说已经发送,我好给分!由于计算相似度,请各位高手们帮忙自己写下,谢谢了~高分悬赏!

最佳答案
  • 二级知识专家网友:woshuo
  • 2021-04-27 18:26

已将答案发到你邮箱


注意查收

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息