FieldPairParse
SRM 249 · 2005-06-29 · by AdminBrett
SRM 249 · 2005-06-29 · by AdminBrett · String Parsing
Problem Statement
Problem Statement
You have been given a document header containing important data that will eventually get stored in a database. The data is formatted as follows:int[] . The return value should be ordered left-to-right based on the positions of the corresponding delimeters in data. If the number of delimiting rectangles is even, return an empty int[] denoting an error.
Field Name Data Field Name Data ... Field Name Data Field Name Data ... ... ... ... ... ...That is, each field name column will be followed by the corresponding data column. If formatted correctly, the header should contain an even number of columns. Each element of data will correspond to a row of values. Since there are no terminating characters or field widths in use, it is not obvious where each column begins and ends. We have decided to use rectangles of spaces to split each column. These rectangles must cover all rows of data, be as wide as possible, and contain only space characters. You will return how wide each delimiting rectangle is in a
Notes
- The input is entirely composed of Xs and spaces since, as far as you are concerned, there are only 2 kinds of characters.
Constraints
- data will contain between 1 and 50 elements inclusive.
- Each element of data will contain between 1 and 50 characters inclusive.
- Each element of data will contain the same number of characters.
- Each character in each element of data will be 'X' or ' ' (quotes for clarity).
- At least one element of data will not begin with a space.
- At least one element of data will not end with a space.
Examples
0)
{
"XXXXX XXXXX",
"XXXX XXXXX "
}
Returns: {3 }
There is one divider here, and it is 3 characters wide.
1)
{
"XXXXXXXXXX XXXXXXXXXXX",
"XXXXXXXXXXXXXXXXX XXXXX"
}
Returns: { }
No divider (which is an error).
2)
{
"X X X",
"X X X"
}
Returns: { }
Two dividers is an error.
3)
{
"XXXX X X X X X",
"XX XXX XX X X X XXX "
}
Returns: {5, 1, 3, 3, 2 }
4)
{"XXXX X X X X X"}
Returns: {6, 2, 11, 1, 3 }
Submissions are judged against all 75 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class FieldPairParse with a public method vector<int> getPairs(vector<string> data) · 75 test cases · 2 s / 256 MB per case