Connection Status:
Competition Arena > RailroadSeatNumeration
SRM 329 · 2006-12-09 · by dmytro · Simple Math, Simple Search, Iteration
Class Name: RailroadSeatNumeration
Return Type: String
Method Name: getInternational
Arg Types: (vector<int>)
Problem Statement

Problem Statement

In a certain European country, railroad cars consist of 9 compartments, each containing 4 seats. There are two possible numeration methods for the seats: the domestic numeration and the international numeration.

  • In the domestic numeration, the seats in the first compartment are numbered 1 through 4, the seats in the second compartment are numbered 5 through 8, and so on.
  • In the international numeration, every seat's number consists of two digits. The first digit is the number of the compartment and the second digit is the number of the seat within that compartment. Compartments are numbered 1 through 9, and the four seats within each compartment are numbered 1, 3, 4, 6 (in the same order as in the domestic numeration).

You are given a int[] tickets containing seat numbers in an unknown numeration. Assuming that every seat number in tickets is in the same numeration, convert them into the international numeration. Return the result as a String containing a single-space separated list of converted numbers in the same order that they are given in the input. If there are several possible return values, return "AMBIGUOUS" (quotes for clarity only). If the input cannot be interpreted as a valid list of seat numbers all in the same numeration, return "BAD DATA" (quotes for clarity only).

Constraints

  • tickets will contain between 1 and 36 elements, inclusive.
  • Each element of tickets will be between 1 and 100, inclusive.
  • tickets will contain no duplicate elements.
Examples
0)
{1}
Returns: "11"

Seat number 1 exists only in the domestic numeration, and it corresponds to seat number 11 in the international numeration.

1)
{11}
Returns: "AMBIGUOUS"

Seat number 11 exists in both numerations, so we cannot figure out which numeration is used here.

2)
{45}
Returns: "BAD DATA"

No seat can be numbered 45 in any numeration.

3)
{5, 7, 6}
Returns: "21 24 23"

Remember to return tickets in the same order as in the input.

4)
{21, 24, 23}
Returns: "AMBIGUOUS"
8)
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36}
Returns: "11 13 14 16 21 23 24 26 31 33 34 36 41 43 44 46 51 53 54 56 61 63 64 66 71 73 74 76 81 83 84 86 91 93 94 96"

1 through 36

9)
{11, 13, 14, 16,  21, 23, 24, 26,  31, 33, 34, 36,  41, 43, 44, 46,  51, 53, 54, 56,  61, 63, 64, 66,  71, 73, 74, 76,  81, 83, 84, 86,  91, 93, 94, 96}
Returns: "11 13 14 16 21 23 24 26 31 33 34 36 41 43 44 46 51 53 54 56 61 63 64 66 71 73 74 76 81 83 84 86 91 93 94 96"

all international tickets

11)
{1 , 24 , 2 , 13 , 11 , 32 , 27 , 28 , 12 , 22 , 15 , 19 , 26 , 34 , 14 , 10 , 23 , 5 , 18}
Returns: "11 66 13 41 34 86 74 76 36 63 44 54 73 93 43 33 64 21 53"

random domestic tickets

12)
{11, 66, 13, 41, 34, 86, 74, 76, 36, 54, 63, 44, 73, 43, 53, 33, 93, 64, 21}
Returns: "11 66 13 41 34 86 74 76 36 54 63 44 73 43 53 33 93 64 21"

random international tickets

18)
{42 , 58 , 21 , 52 , 53 , 76 , 43}
Returns: "BAD DATA"

random test

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

Coding Area

Language: C++17 · define a public class RailroadSeatNumeration with a public method string getInternational(vector<int> tickets) · 175 test cases · 2 s / 256 MB per case

Submitting as anonymous