TextColumns
TCCC '04 Semifinals 2 · 2004-02-23 · by Yarin
Problem Statement
An OCR program (optical character recognition) needs to perform other things than just recognizing letters. One of these things is mapping out the page layout. In this problem, you should solve the similar, but easier task, of concatenating text spread across several text columns.
The input text will be given as a
{" This is put it that ",
" a text all is ",
"in several together nicely ",
"columns. into a formatted. ",
" single ",
" Your job text ",
"is to Good luck! "}
The text above obviously has three text columns. Formally, text columns are always separated where there are three or more consecutive empty character columns (i.e. the only character in those columns are space). Furthermore, text columns can't be empty (see example 3).
You should also find all paragraphs. The paragraph splits occur on blank lines within a text column. Only blank lines between the first and last row used in a text column should be considered. In the text above, the last line in column two is empty, but this is not a paragraph split because there is no text below this line in the same text column.
The return value should contain the same text, in a
Create a class TextColumns containing the method formatText which takes
a
Constraints
- text will contain between 1 and 50 elements inclusive.
- Each element in text will contain between 1 and 50 characters, inclusive.
- All elements in text will contain the same number of characters.
- text will only contain the characters 'A'-'Z', 'a'-'z', '0'-'9', '.', ',', '!', '?' and space.
- At least one character in text will not be a space.
{" This is put it that ",
" a text all is ",
"in several together nicely ",
"columns. into a formatted. ",
" single ",
" Your job text ",
"is to Good luck! "}
Returns: { "This is a text in several columns.", "Your job is to put it all together into a single text that is nicely formatted.", "Good luck!" }
This is the example in the problem statement.
{"This is ",
"just one ",
"column ",
" ",
"a l ",
" b m ",
" c n ",
" d o ",
" e p ",
" f q ",
" g r ",
" h s ",
" i t ",
" j u ",
"k v "}
Returns: { "This is just one column", "a l b m c n d o e p f q g r h s i t j u k v" }
{" ",
" ",
" Some text ",
" here and ",
" some ",
" ",
" new ",
" over",
" here ",
" text ",
" there ",
" ",
" ",
" And ",
" something ",
" ",
" ",
" Finito ",
" "}
Returns: { "Some text here and some text there", "And something new over here", "Finito" }
{"a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y ","z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z ","a b c d e f g h i j k l m n o p q r s t u v w x y ","A B C D E F G H I J K L M N O P Q R S T U V W X Y "}
Returns: { "a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y z Z . , ! ? z Z . , ! ? z Z . , ! ? z Z . , ! ? z a b c d e f g h i j k l m n o p q r s t u v w x y A B C D E F G H I J K L M N O P Q R S T U V W X Y" }
{"! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !","! !",". ."}
Returns: { "! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! . ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ." }
Submissions are judged against all 35 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TextColumns with a public method vector<string> formatText(vector<string> text) · 35 test cases · 2 s / 256 MB per case