Justifier
SRM 164 · 2003-09-20 · by dgoodman
SRM 164 · 2003-09-20 · by dgoodman · String Manipulation
Problem Statement
Problem Statement
We have a collection of String s, and we want to right justify them.
Create a class Justifier that contains a method justify that is
given a String[] textIn and returns
a String[] containing the same String s, right justified, in the same order as they
appear in textIn.
The returned
Constraints
- textIn will contain between 1 and 50 elements inclusive
- each element of textIn will contain only uppercase letters 'A'-'Z'
- each element of textIn 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 24 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Justifier with a public method vector<string> justify(vector<string> textIn) · 24 test cases · 2 s / 256 MB per case