Connection Status:
Competition Arena > FloorLayout
SRM 383 · 2007-12-13 · by StevieT · String Parsing
Class Name: FloorLayout
Return Type: int
Method Name: countBoards
Arg Types: (vector<string>)
Problem Statement

Problem Statement

You are building a house and are about to lay the floorboards in a particular room. Your architect has designed the layout of the floorboards and you now want to know how many boards you need to buy. Each board is 1 unit wide and can be of any positive integer length. The room is rectangular and the boards are to be laid out on a unit-square grid inside the room, parallel to the walls of the room.


You are given a String[] layout describing the layout of the floorboards. Character j of element i of layout describes the grid-square at position (i, j) and will either be a '-' or a '|', depending on which direction the floorboard covering that square is oriented. If two '-' characters are adjacent at the same value of i, then they form part of the same east/west-oriented floorboard. Similarly, if two '|' characters are adjacent at the same value of j, they are part of the same north/south-oriented floorboard. Return an int containing the number of distinct floorboards in the layout.

Constraints

  • layout will contain between 1 and 50 elements, inclusive.
  • Each element of layout will contain between 1 and 50 characters, inclusive.
  • Each element of layout will contain the same number of characters.
  • Each character in layout will be a '-' or a '|'.
Examples
0)
{"----"
,"----"
,"----"
,"----"}
Returns: 4

This layout contains 4 boards laid east/west.

1)
{"-||--||--"
,"--||--||-"
,"|--||--||"
,"||--||--|"
,"-||--||--"
,"--||--||-"}
Returns: 31

This is an aesthetic pattern made up of boards of lengths 1 and 2.

2)
{"--------"
,"|------|"
,"||----||"
,"|||--|||"
,"||----||"
,"|------|"
,"--------"}
Returns: 13
3)
{"||-||-|||-"
,"||--||||||"
,"-|-|||||||"
,"-|-||-||-|"
,"||--|-||||"
,"||||||-||-"
,"|-||||||||"
,"||||||||||"
,"||---|--||"
,"-||-||||||"}
Returns: 41
4)
{"-||--|"
,"||||||"
,"|||-|-"
,"-||||-"
,"||||-|"
,"||-||-"}
Returns: 19

Submissions are judged against all 62 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FloorLayout with a public method int countBoards(vector<string> layout) · 62 test cases · 2 s / 256 MB per case

Submitting as anonymous