TopCoder problem "YoungBrother" used in TCHS SRM 44 (Division I Level One)



Problem Statement

    

John wrote some text in his text editor. The text contained exactly n lines, each of which was exactly k characters long. His younger brother came along later and might have added some line breaks in random places and removed some of the original line breaks. Fortunately, he did not delete any of the original characters. John wants to restore his original text and he needs your help.

You will be given a String[] lines containing the state of the text editor after the brother's edits. Return a String[] containing exactly n elements of length k representing the original text.

 

Definition

    
Class:YoungBrother
Method:restoreWords
Parameters:String[], int, int
Returns:String[]
Method signature:String[] restoreWords(String[] lines, int n, int k)
(be sure your method is public)
    
 

Constraints

-lines will contain between 1 and 50 elements, inclusive.
-Each element of lines will contain between 0 and 50 characters, inclusive.
-Each element of lines will contain only lowercase letters ('a'-'z').
-n will be between 1 and 50, inclusive.
-k will be between 0 and 50, inclusive.
-lines will contain exactly n * k characters.
 

Examples

0)
    
{"jhgu", "", "a", "kjl"}
2
4
Returns: {"jhgu", "akjl" }
John's brother added one line break at the end of the first line, and another line break after the first character of the second line.
1)
    
{"","",""}
1
0
Returns: {"" }
The original text might have contained words of length 0.
2)
    
{"","","","","vhtoqhthisojnovivdavhafa","wjbjtwwxuglxceeypnnvkuxwolaycvrwtdaugej","",""}
3
21
Returns: {"vhtoqhthisojnovivdavh", "afawjbjtwwxuglxceeypn", "nvkuxwolaycvrwtdaugej" }
3)
    
{"tkwyslbgxegjvdaafcnxhetx","xwuqmvepmkxl"}
6
6
Returns: {"tkwysl", "bgxegj", "vdaafc", "nxhetx", "xwuqmv", "epmkxl" }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8252

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10795&pm=8252

Writer:

boba5551

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Simple Search, Iteration, String Manipulation