google中国编程赛的俩题 NO1!请高手做!

来源:百度知道 编辑:UC知道 时间:2024/07/11 00:09:23
NO1.
Problem Statement
????
You are given a String[] cityMap representing the layout of a city. The city consists of blocks. The first element of cityMap represents the first row of blocks, etc. A 'B' character indicates a location where there is a bus stop. There will be exactly one 'X' character, indicating your location. All other characters will be '.'. You are also given an int walkingDistance, which is the maximum distance you are willing to walk to a bus stop. The distance should be calculated as the number of blocks vertically plus the number of blocks horizontally. Return the number of bus stops that are within walking distance of your current location.
Definition
????
Class:
BusStops
Method:
countStops
Parameters:
String[], int
Returns:
int
Method signature:
int countStops(String[] cityMap, int walkingDistance)
(be sure your method is public)
????

Constraint

为了方便大家编程,我翻译了一下,E文不够好,自己想了之后翻译的,但是基本意决对够正确。刚掉线了,到现在才发上来。

问题描述

现在给你一个字符串数组cityMap来表示一个城市的布局。这个城市由多个街区组成。字符串数组cityMap的第一个元素表示这些街区的第一行,等等。用字符'B'表示巴士站的位置。使用字符'X'表示你的位置。剩下的用字符'.'表示。

给你一个整型变量walkingDistance,用来表示你走到巴士站的最大距离。距离由竖直的街区数加上水平的街区数计算得到。返回在你当前位置的walkingDistance范围内巴士站的个数。

定义下列结构:
类 BusStops
它的方法有
countStops
参数
String[], int
返回值
int
使用方法
int countStops(String[] cityMap, int walkingDistance)
(保证这个方法是公共的Public)

规定
-
字符串数组cityMap的元素个数在1-50以内(包括1,50)
-
cityMap的每个元素要有1-50个字符(包括1,50)
-
cityMap的每个数组元素的字符个数要相同
-
每个元素的字符集为{'B', 'X', '.'}(就是只字符只能是'B', 'X', '.')
-
数组cityMap中,一共只能有一个'X'
-
walkingDistance 取值为1-100,包括1, 100

例1)
cityMap =
{". . . B .",
". . . . .",
". . X . B",
&q