Connection Status:
Competition Arena > TapeMeasure
SRM 789 · 2020-08-28 · by misof · Simple Math, Simple Search, Iteration, String Manipulation
Class Name: TapeMeasure
Return Type: String[]
Method Name: draw
Arg Types: (int, int)
Problem Statement

Problem Statement

Here's the beginning of an ASCII art bitmap that depicts a tape measure:

###################################################
# # # # # # # # # # # # # # # # # # # # # # # # # #
#         #         #         #         #         #
#                   #                   #          
0                   10                  20         

A more formal description:

  • The first row is full of '#' marks and represents the top edge of the tape measure.
  • The second row shows unit marks in every second column.
  • Multiples of five get a longer mark that continues into the third row.
  • Multiples of ten get a mark that reaches all the way into the fourth row, and they also get labels in the fifth row. The label always begins in the column with the mark and extends to the right as needed.

You are given the ints leftMark and rightMark. Construct the drawing of the part of the tape measure that begins with the column containing the mark for number leftMark and ends with the column that contains the mark for the number rightMark. Return the drawing as a String[].

Constraints

  • leftMark will be between 0 and 999, inclusive.
  • rightMark will be between leftMark and 999, inclusive.
  • rightMark - leftMark will be at most 25.
Examples
0)
0
25
Returns: {"###################################################", "# # # # # # # # # # # # # # # # # # # # # # # # # #", "#         #         #         #         #         #", "#                   #                   #          ", "0                   10                  20         " }

This is the exact example shown in the problem statement.

1)
981
990
Returns: {"###################", "# # # # # # # # # #", "        #         #", "                  #", "0                 9" }

Note how the labels for marks 980 and 990 are partially visible in this section of the tape measure. Below we show a section of the tape measure that is one mark wider on each side (left=980, right=991) so that you can see these labels completely. ####################### # # # # # # # # # # # # # # # # # 980 990

2)
20
20
Returns: {"#", "#", "#", "#", "2" }
3)
31
38
Returns: {"###############", "# # # # # # # #", "        #      ", "               ", "               " }
4)
64
75
Returns: {"#######################", "# # # # # # # # # # # #", "  #         #         #", "            #          ", "            70         " }

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

Coding Area

Language: C++17 · define a public class TapeMeasure with a public method vector<string> draw(int leftMark, int rightMark) · 107 test cases · 2 s / 256 MB per case

Submitting as anonymous