2023 HUAWEI OD Unified Exam B Paper [Looking for a Parking Space] Java Implementation

Table of contents  

topic

train of thought

Code


topic

There is a row of parking spaces in the parking lot, 0 means no parking, 1 means there are cars. At least one car is parked in the parking space, and at least one vacant space is not parked. In order to prevent scratches, it is necessary to find a parking space for the parker, so that the distance from the nearest vehicle to the parker's car is the largest. Return the maximum distance at this time .

enter description

1. A string of parking signs separated by half-width commas. The parking sign is 0 or 1, 0 is empty, and 1 is parked.

2. There are up to 100 parking spaces.

output description

Output an integer to record the maximum distance

Example 1:

enter:

1,0,0,0,0,1,0,0,1,0,1

output:

2

 input Output

        Since the input data and output data of the computer test generally have multiple sets (indeterminate), and the format is various, how to deal with the input and output of the question is one of the most basic requirements for everyone. This is also a big problem that plagues beginners.

1. Input

Format 1: Scanner sc = new Scanner (new BufferedI

Guess you like

Origin blog.csdn.net/misayaaaaa/article/details/132293019