Connection Status:
Competition Arena > JustifyText
SRM 233 · 2005-03-03 · by lars2520 · String Manipulation
Class Name: JustifyText
Return Type: String[]
Method Name: format
Arg Types: (vector<string>)
Problem Statement

Problem Statement

We have a collection of Strings, and we want to right justify them. Given a String[] text, your task is to return a String[] containing the same Strings, right justified, in the same order as they appear in text.

The returned Strings should be padded on the left with space characters so that they are all the same length as the longest String in textIn.

Constraints

  • text will contain between 1 and 50 elements inclusive
  • each element of text will contain only uppercase letters 'A'-'Z'
  • each element of text will contain between 1 and 50 characters inclusive
Examples
0)
{"BOB","TOMMY","JIM"}
Returns: {"  BOB", "TOMMY", "  JIM" }

The longest String is "TOMMY" which has 5 characters. So the returned Strings all contain exactly 5 characters.

1)
{"JOHN","JAKE","ALAN","BLUE"}
Returns: {"JOHN", "JAKE", "ALAN", "BLUE" }

No padding is necessary since they all contain the same number of characters.

2)
{"INTERNATIONALIZATION"}
Returns: {"INTERNATIONALIZATION" }
3)
{"AL","BOB","JOHN","JIMMY","HAROLD","DOUGLAS","JONATHON"}
Returns: {"      AL", "     BOB", "    JOHN", "   JIMMY", "  HAROLD", " DOUGLAS", "JONATHON" }
4)
{"LONGEST","A","LONGER","SHORT"}
Returns: {"LONGEST", "      A", " LONGER", "  SHORT" }

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

Coding Area

Language: C++17 · define a public class JustifyText with a public method vector<string> format(vector<string> text) · 27 test cases · 2 s / 256 MB per case

Submitting as anonymous