Sample Questions from the 2021 Contest

Blue Track

1. Electric Charges

In this problem you need to calculate the total amount of an electric bill. Given an integer value representing the number of kilowatt hours used, calculate the total amount owed using the following rates:

7.633 cents for the first 1000 hours used
9.259 cents for any hours used over 1000 hours.

Input

Prompt for the input as shown below. Enter an integer greater than zero representing the kilowatt hours used. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

A decimal value representing the total amount owed in dollars. Although the results in the test data below show multiple decimal positions, your answers will only be checked to two decimal positions.

Test Data

InputOutput
Enter the KW hours used: 1500Amount owed is $122.625
Enter the KW hours used: 764
Amounted owed is $58.31612
Enter the KW hours used: 1215
Amounted owed is $96.23685
Enter the KW hours used: 812Amounted owed is $61.97996

Fun with Commas

In this problem you must separate each word in a list, except the last, with commas. The last word must be prefaced by the word “and”. Each word will be entered on the console on its own line. The list will have at least one word and a maximum of fifty words. The list will be terminated with the word “quit”. For example, input consisting of:

one
two
three
quit

will result in the following output: one, two and three.

Input

Prompt for the input as shown below. Enter a list of words of various lengths ending with the word quit. The list will have a minimum of one word and a maximum of fifty words. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

The list of words with each pair of words separated by a comma except for the last.  The last pair of words are separated by the word "and".

Test Data

InputOutput
Enter next word or quit: one
Enter next word or quit: two
Enter next word or quit: three
Enter next word or quit: quit
one, two and three
Enter next word or quit: 1
Enter next word or quit: 2
Enter next word or quit: 3
Enter next word or quit: 4
Enter next word or quit: 5
Enter next word or quit: 6
Enter next word or quit: quit
1, 2, 3, 4, 5, and 6
Enter next word or quit: apples
Enter next word or quit: peaches
Enter next word or quit: plums
Enter next word or quit: pears
Enter next word or quit: quit
apples, peaches, plums and pears
Enter next word or quit: one
Enter next word or quit: two
Enter next word or quit: quit
one and two
Enter next word or quit:one
Enter next word or quit:quit
one

3.  Largest Quotient

Using an array of integers, your application will need to calculate the largest number possible by dividing any two integers in the array. For example, if the array contained 5, 4, 19, 20, 33, the largest number possible is 8 calculated as 33 / 4. Display the integer result. Truncate any decimal digits.

Input

Prompt for the input as shown below. Enter a series of integers each separated by a space. The final digit will be a zero indicating the end of the input. The series of integers will contain only positive (non-zero) integers. The series will contain at least two integers and fewer than 15. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

A single integer number representing the largest quotient possible using the input.

Test Data

InputOutput
Enter integers separated by a space.
End with 0: 4 5 33 20 19 0
8
Enter integers separated by a space.
End with 0: 35 19 4 33 21 5 17 8 3 42 22 26 14 9 0
14
Enter integers separated by a space.
End with 0: 18 44 0
2
Enter integers separated by a space.
End with 0: 77 32 27 41 18 7 0
11
Enter integers separated by a space.
End with 0: 108 102 103 99 105 190 107 101 109 33 111 112 113 114 22 0
8
Enter integers separated by a space.
End with 0: 44 9 18 23 7 34 8 19 0
6
Enter integers separated by a space.
End with 0: 5 5 5 5 5 0
1

4.  Where Am I?

In this problem you will need to determine which quadrant a given point is in. There are four quadrants, numbered from 1 to 4, as shown in the diagram below. Given the X, Y coordinates of a point display 1, 2, 3, or 4 to indicate the quadrant in which the point is located.

Image showing a black vertical and horizontal arrow, with the numbers 2,1,3 and 4 showing in each corner of the intersecting arrows.  Each quandrant of the intersecting arrows show a pair of numbers in parenthesis.  In the upper left-hand quandrant with the number 2 showing, -15 and 30 are showing in parenthesis.  In the upper right-hand quandrant with the number 1 showing, 15, 30 are showing in parenthesis.  In the lower right-hand quandrant with the number 4 showing, 15 and -30 are showing in parenthesis.  In the lower left-hand quandrant with the number 3 showing, -15 and -30 are showing in parenthesis.

Input

Prompt for the input as shown below. Enter two integers separated by a space. Neither number can be zero. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

Output the quadrant number (1, 2, 3 or 4) for the point. Use the format shown below.

Test Data

InputOutput
Enter X and Y separated by a space: 45 90Q 1
Enter X and Y separated by a space: -10 -95
Q 3
Enter X and Y separated by a space: -40 50
Q 2
Enter X and Y separated by a space: 88 -67
Q 4

5.  What's the Difference?

In this problem you will process two lists of numbers and return the difference. The difference are numbers that appear in one of the lists but not both. Consider the following two lists:

[27, 19, 1, 7]
[7, 23, 14, 9, 27]

The difference would be: [1, 9, 14, 19, 23].

Input

Prompt for the input as shown below. Enter two lines of integers with each integer separated by a space. The first line of input will start with the number of items in the list, n. Following are n integers each separated by a single space. The second line of input will also start with the number of items in the second list, m. This is followed by m integers each separated by a single space. The lists can contain any valid integer including negative numbers and zero. The same number will not appear twice in the same list. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

Display the differences between the two lists. The numbers in the list must by displayed in ascending sequence. Display a message, as shown below, if there are no differences.

Test Data

Ignore the line wrap in the fourth test case.

InputOutput
Enter first set of data separated by space:
4 7 19 1 27
Enter second set of data separated by space:
5 7 23 14 9 27
1 9 14 19 23
Enter first set of data separated by space:
3 1 2 3
Enter second set of data separated by space:
3 3 2 1
No differences
Enter first set of data separated by space:
4 45 8 19 2
Enter second set of data separated by space:
4 66 33 12 8
2 12 19 33 45 66
Enter first set of data separated by space:
10 99 23 109 8932 -87 123 13 0 3945 1450
Enter second set of data separated by space:
8 8932 77 340 87 202 13 10 1450
-87 0 10 23 77 87 99 109 123 202 340 3945
Enter first set of data separated by space:
4 2 4 8 6
Enter second set of data separated by space:
5 9 7 5 3 1
1 2 3 4 5 6 7 8 9

6.  Glad to be One

The Glad to be One number sequence are those whose sequence ends in a one. Numbers that are not “glad” are those that infinitely repeat a sequence of numbers but never reach the number one. For this problem you must determine if a number is a glad number or not. For a given positive integer N, the next number in the sequence will be the sum of the squares of its digits. Continue to generate numbers in the sequence until the sequence reaches one or the sequence begins to repeat itself. The original input is a glad number if the sequence reaches one. The original input is not a glad number if the sequence starts to repeat itself without reaching one. Below are examples.

Example 1Example 2
Original input: 49
Sequence generated:
49 -> 97 -> 130 -> 10 -> 1
Output: Glad Number
The sequence was generated as follows:
42 + 92 = 97
92 + 72 = 130
12 + 32 + 02 = 10
12 + 02 = 1
Original input:  11
Output: Not a Glad Number
The sequence was generated as follows:
12 + 12 = 2
22 = 4
42 = 16
12 + 62 = 37
32 + 72 = 58
52 + 82 = 89
82 + 92 = 145
12 + 42 + 52 = 42
42 + 22 = 20
22 + 02 = 4
Sequence will repeat and not reach 1

Input

Prompt for the input as shown below. Enter an integer number > 0. You do not need to edit this data. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

Glad Number or Not a Glad Number

Test Data

InputOutput
Enter a positive integer:  49Glad Number
Enter a positive integer:  11
Not a Glad Number
Enter a positive integer:  97
Glad Number
Enter a positive integer:  1234
Not a Glad Number

7.  Less or More

In this problem you must examine a list of numbers and determine how many times a number in the list has a lower number to its “right”. For example, in the list 3, 9, 4, 6, 7, 5, there are 3 cases where a number in the list has at least one lower number to the right. The number 9 has the number 4 to its right. The number 6 has the number 5 to its right. The number 7 has the number 5 to its right.

Input

Prompt for the input as shown below. Enter an integer, n, that represents the count of numbers to follow. Enter n integers with each separated by a space. Each integer will be greater than 0. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

A count of how many times a number in the list has a lower number to its right.

Test Data

InputOutput
Enter count, integers separated by a space:
6 28 7 6 21 88 89
2
Enter count, integers separated by a space:
10 13 99 4 18 44 87 109 201 22 1
9
Enter count, integers separated by a space:
5 13 22 77 83 91
0
Enter count, integers separated by a space:
7 85 74 32 21 20 16 2
6

8.  It Adds Up

In this problem you will be given a target number and a list of numbers to search. You will need to identify all pairs of numbers that sum to the target number. For example, given the target number of 6 and the list of 16, 11, 2, 8, 6, 7, 4, 33, -2, the pairs (2, 4) and (8, -2) sum to 6. In addition to listing the pairs that sum to the target number, you will need to list their position in the original list. The pair (2, 4) was located at 3 and 7. The pair (8, -2) was located at 4 and 9.

Input

Prompt for the following integer values. The first integer value will be a positive or negative integer or zero and will represent the target sum. The second integer is the number of numbers (N) in the list. This is followed by N positive or negative integers, or zero. Each integer value will be separated by a space. Data will be entered from the console. You do not need to edit the input data. Rerun your application to test each test case.

Output

Display each pair of numbers that sum to the target number formatted as shown below. This is followed by the location of each number formatted as shown below. Display “No pairs found” if there are no pairs that sum to the target number.

Test Data

InputOutput
Enter the desired sum, number of elements, each element:
6 9 16 11 2 8 6 7 4 33 -2
(2, 4) found at [3] [7]
(8, -2) found at [4] [9]
Enter the desired sum, number of elements, each element:
13 11 8 5 4 3 7 12 6 1 19 -4 17
(8, 5) found at [1] [2]
(7, 6) found at [5] [7]
(12, 1) found at [6] [8]
(-4, 17) found at [10] [11]
Enter the desired sum, number of elements, each element:
33 6 1 14 99 23 18 6
No pairs found
Enter the desired sum, number of elements, each element:
24 10 13 12 24 19 6 5 0 27 -3 7
(24, 0) found at [3] [7]
(19, 5) found at [4] [6]
(27, -3) found at [8] [9]

Gold Track

1.  Find the Missing Side

In this problem you’ll be given the length of two sides of a right triangle and need to calculate the name and length of the third side. The two given sides can change. In other words, the same two sides are not always provided. Review the right triangle below.

Image showing a black-lined triangle with the letter A in the top angle, letter B at the bottom angle and the letter C at the lower right corner angle.

The right triangle has sides AB, BC, and AC. Side AC is always the hypotenuse. Assume you are given the following input: AB is 3, BC is 4. Your application must identify the missing side as AC and the length as 5.

Input

The application should prompt for and read: (a) the name of the first side, (b) the length of the first side, (c) the name of the second side, (d) the length of the second side. The lengths will be integer values greater than one. The names will be two characters based on the figure above. Values will be AB, BC, or AC. Only valid data will be entered. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

The name of the missing side and the length of the missing side. Any decimal positions in the length of the missing side must be dropped not rounded.

Test Data

InputOutput
Enter first segment: AB
Enter first length: 3
Enter second segment: BC
Enter second length: 4
AC 5
Enter first segment: AC
Enter first length: 891
Enter second segment: AB
Enter second length: 125
BC 882
Enter first segment: BC
Enter first length: 1923
Enter second segment: AC
Enter second length: 9999
AB 9812

Additional Information:

  1. You do not need to handle exceptions.
  2. Add your name as a comment in the first line in your source code. Add the following after your name: “Gold #1”.
  3. The judges will test your application with a different set of data that will have a different number of test cases.

2.  Single Digit

In this problem you will start with a single positive number. Subtract adjacent pairs of digits in that number to get the absolute value of their difference. Each result is used to generate a new number. Repeat that process as many times as necessary to arrive at a number that is a single digit. Display the final single digit.

This example starts with 584. The first iteration produces the following interim values.

| 5 – 8 | = 3 | 8 – 4 | = 4

The process is repeated for 34.

| 3 – 4 | = 1

The result is 1.

Input

Prompt for the input as shown below. Enter a single integer value greater than zero. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

The single digit that is the final result from successively subtracting adjacent digits in the number.

Test Data

InputOutput
Enter the number:  55
Enter the number:  987650
Enter the number:  1287453

Additional Information:

  1. You do not need to handle exceptions.
  2. Add your name as a comment in the first line in your source code. Add the following after your name: “Gold #2”.
  3. The judges will test your application with a different set of data that will have a different number of test cases.

3.  Agreeable Numbers

In this problem, agreeable numbers are two different numbers where the sum of the divisors of one number are equal to the other number. Given two numbers X and Y, the divisors of X sum to Y and the divisors of Y sum to X. A divisor of a number is a positive factor of that number other than the number itself. In other words, a number N is a divisor of X, if dividing X by N leaves no reminder. The smallest pair of agreeable numbers is (220, 284). They are agreeable because the divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110, which sum to 284 and the divisors of 284 are 1, 2, 4, 71 and 142, which sum to 220. You will be given two integer numbers and must determine if these are agreeable numbers.

Input

Prompt for the input as shown below. Enter two positive integer numbers separated by a space. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

The phrase “Agreeable numbers” if the two numbers are agreeable. The phrase “Not agreeable numbers” if the two numbers are not agreeable.

Test Data

InputOutput
Enter two numbers separated by a space:
220 284
Agreeable numbers
Enter two numbers separated by a space:
8023 2987
Not agreeable numbers
Enter two numbers separated by a space:
17296 18416
Agreeable numbers
Enter two numbers separated by a space:
4523 4912
Not agreeable numbers
Enter two numbers separated by a space:
2620 2924
Agreeable numbers

Additional Information:

  1. You do not need to handle exceptions.
  2. Add your name as a comment in the first line in your source code. Add the following after your name: “Gold #3”.
  3. The judges will test your application with a different set of data that will have a different number of test cases.

4.  Reverse the Array (Many Times)

In this problem you will build a new array using the numbers from an existing array. Add each number, one at a time, to the end of the new array. Then reverse the order of the numbers in the new array. Repeat this for each number added. For example, given the array [1, 2, 3, 4]. Add the first element [1] to the end of a new array and reverse it. Then add the second element [2] to the end of the new array and reverse the array. Repeat this process n times where n is the size of the array. The result is the array [4, 2, 1, 3]. Below are the detailed steps for the array [1, 2, 3, 4].


Add next element to endReverse the array
1[1]
[1]
2[1, 2]
[2, 1]
3[2, 1, 3]
[3, 1, 2]
4[3, 1, 2, 4]
[4, 2, 1, 3]

Here is another example starting with the original array [4, 8, 6, 1, 7, 9] and ending with a result of [9, 1, 8, 4, 6, 7].


Add next element to endReverse the array
1[4]
[4]
2[4, 8]
[8, 4]
3[8, 4, 6]
[6, 4, 8]
4[6, 4, 8, 1]
[1, 8, 4, 6]
5[1, 8, 4, 6, 7]
[7, 6, 4, 8, 1]
6[7, 6, 4, 8, 1, 9]
[9, 1, 8, 4, 6, 7]

Input

Prompt for the input as shown below. Enter an integer, N, that represents the count of numbers to follow. N will be greater than 0. Enter N integers with each integer separated by a space. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

A list of integers, each separated by a space, representing the final result.

Test Data

InputOutput
Enter count, integers separated by a space:
6 4 8 6 1 7 9
9 1 8 4 6 7
Enter count, integers separated by a space:
4 1 2 3 4
4 2 1 3
Enter count, integers separated by a space:
7 33 18 97 108 13 11 9
9 13 97 33 18 108 11

Additional Information:

  1. You do not need to handle exceptions.
  2. Add your name as a comment in the first line in your source code. Add the following after your name: “Gold #4”.
  3. The judges will test your application with a different set of data that will have a different number of test cases.

5.  String Sort

In this problem you will need to sort a list of words based on their length. The shortest word must be first and the longest word must be last. Words of the same length may be in any order within that length. Given the list of words: fourteen, forty, thirty, one, three, the sorted list will be: one, forty, three, thirty, fourteen.

Input

Prompt for and read the number of words, N, to be entered. Prompt for and enter N words. N will be positive and greater than 0. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

Display the list of words in order by their length. The shortest word must be first and the longest word must be last. Words of the same length may be in an order.

Test Data

InputOutput
Enter count of words: 5
Enter next word: fourteen
Enter next word: forty
Enter next word: thirty
Enter next word: one
Enter next word: three
one forty three thirty fourteen
Enter count of words: 3
Enter next word: century
Enter next word: millennium
Enter next word: eon
eon century millennium
Enter count of words: 6
Enter next word: ravens
Enter next word: chiefs
Enter next word: steelers
Enter next word: raiders
Enter next word: buccaneers
Enter next word: hawks
hawks ravens chiefs raiders steelers buccaneers

Additional Information:

  1. You do not need to handle exceptions.
  2. Add your name as a comment in the first line in your source code. Add the following after your name: “Gold #5”.
  3. The judges will test your application with a different set of data that will have a different number of test cases.

6.  Load Rocks

The Rockland Quarry stores rocks in bags. The first bag on the shelf has 1 pound of rocks, the next bag has 2 pounds of rocks, the next has 3 pounds of rocks and so on. The quarry has an unlimited number of bags of rocks. In other words, the heaviest bag stored weighs as much as the largest integer value. A customer specifies a weight when ordering rocks. Rocky, the forklift operator, always takes bags from adjacent locations to meet the required weight. He also always takes a minimum of two bags. You must write an application to help Rocky find all the possible combinations of rock bags with consecutive weights that will total the weight the customer ordered. For example, Bobby Stone has ordered 15 pounds of rock. There are 3 combinations of consecutive weights that will add to 15. These are:

  • 1 + 2 + 3 + 4 + 5 = 15
  • 4 + 5 + 6 = 15
  • 7 + 8 = 15

For some large orders the number of combinations could be quite high and result in a large amount of output. To reduce the amount of output and still prove the application works the owner, Mr. Slate, has agreed to accept two pieces of data instead. The first is the number of combinations that meet the criteria. The second is the sum of the first number in each combination. For an order of 15 pounds the output would be 3 and 12. The 12 was calculated as 1 + 4 + 7.

Input

Prompt for and read the weight of rocks on order. The weight of rocks will be a positive integer greater than 2. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

Display the number of bag combinations that will total the order weight followed by the sum of the first number in each combination.

Test Data

InputOutput
Enter weight of rock order: 15
3 12
Enter weight of rock order: 3
1 1
Enter weight of rock order: 26754
15 28351
Enter weight of rock order: 100
2 27

Additional information:

  1. You do not need to handle exceptions.
  2. Add your name as a comment in the first line in your source code. Add the following after your name: “Gold #6”.
  3. The judges will test your application with a different set of data that will have a different number of test cases.

7.  Eliminate Unlucky Numbers

In this problem you will generate a lucky number by manipulating a list of odd numbers. The user will enter a number (n) indicating the number of “passes” through the list. The first pass is to generate a list of positive odd integers. The list will be composed of the first 10,000 odd numbers. On the second pass, eliminate every third number from the list. This is because 3 is the 2nd number in the original list and this is the 2nd pass. On the third pass, eliminate every 7th number in the revised list. This is because 7 is the 3rd number in the revised list and this is the 3rd pass. If the user entered 4 for n, then the next pass is to display the 4th number in the revised list. The fourth number will be 9. This is the lucky number for a user entered value of 4. For example:

Original list (pass one): 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 … 19999

Revised list (pass two) after eliminating every 3rd number (which was the 2nd number in the list above) 1 3 7 9 13 15 19 21 25 27 31 33 37 39 43 45 49 51 55 57 … (5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65 … were eliminated)

Revised list (pass three) after eliminating every 7th number (which was the 3rd number in the revised list) 1 3 7 9 13 15 21 25 27 31 33 37 43 45 49 51 55 57 … (19, 39, 61, 81, 103 … were eliminate)

The lucky number is the 4th number in the revised list.

Input

Prompt for and read a single positive integer between 1 and 2066 inclusive. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

The nth number in the revised list after n – 1 passes as described above.

Test Data

InputOutput
Enter n: 4
9
Enter n: 11
Enter n: 26
115
Enter n: 5
13
Enter n: 2066
19993

Additional Information:

  1. You do not need to handle exceptions.
  2. Add your name as a comment in the first line in your source code. Add the following after your name: “Gold #7”.
  3. The judges will test your application with a different set of data that will have a different number of test cases.

8.  Museum Tour

In this problem, you must follow a set of instructions to travel through the rooms of a museum. The museum is housed in a rectangular building. The building is divided into equal size rooms that can be defined by a grid of a fixed number of rows and columns. Rooms on the outside have doors on their exterior walls to allow entry from the outside. However, corner rooms can only be entered from the north or south. Corner rooms can’t be entered from the east or west. An interior room can be accessed from any adjacent room. The goal is to identify valid museum tours. A valid tour is one that never visits the same room twice and ends with the last instruction causing you to exit the museum.

For each museum tour you are given the grid describing the museum rooms in the form of the number of rows (r) and columns (c). You are also given a starting room. Finally, you are given a series of instructions on how to walk through the rooms. There are three instructions represented by the numbers 0, 1, and 2. Zero is to move straight forward one room. One represents a move one room to the right. A two represents a move one room to the left.

Example One

For this example, the museum has 4 rows and 3 columns. The starting room is S at (0,2). The instructions are 0, 0, 0, 1, 0, 1, 1, 2, 0, 0. The first instruction (0) is to move ahead 1 room placing you in room (1,2). The next instruction (0) is to move ahead 1 room placing you in room (2,3). The next instruction (0) is to move ahead 1 room placing you in room (3,2). The next instruction (1) is to move into the room on your right placing you in room (3,1). The next instruction (0) is to move 1 room ahead placing you in room (3,0). The next instruction (1) is to move into the room on your right placing you in room (2,0). The next instruction (1) is to move into the room on your right placing you in room (2,1). The next instruction (2) is to move into the room on your left placing you in room (1,1). The next instruction (0) is to move 1 room ahead placing you in room (0,1). The next instruction (0) is to move 1 room ahead placing you outside the museum to successfully complete your tour.

Image showing a black-lined square grid with the numbers 0, 1, 2 across the top and 0, 1, 2, and 3 going down on the outside of the grid.  The word North and showing to the left of the grid with a black arrow pointing upward.  The letter S is shown in the upper right-hand corner of the grid and black arrows are shown in different grid boxes.

For this example, the museum again has 4 rows and 3 columns. The starting room S is (0,1). The instructions are 2, 0, 0, 1, 2. The first instruction (2) is to move into the room on your left placing you in room (0,2). The next move (0) is move ahead 1 room. This causes you to exit the museum. Since you still have tour instructions remaining, you have left the building before the tour was over.

Image showing a black-lined square grid with the numbers 0, 1, 2 across the top and 0, 1, 2, and 3 going down on the outside of the grid.  The word North and showing to the left of the grid with a black arrow pointing upward. The letter S is shown in the middle top row box of the grid and 3 black arrows are shown in different grid boxes.

For this example, the museum still has 4 rows and 3 columns. The starting room is (2,2). The instructions are 0, 2, 2, 2, 0, 1. The first instruction (0) is to move ahead 1 room placing you in room (2,1). The next instruction (2) is to move into the room on your left placing you in room (3,1). The next instruction (2) is to move into the room on your left placing you in room (3,2). The next instruction (2) is to move into the room on your left placing you in room (2,2). This is the second time you have been in this room making this an invalid tour because you have visited the same room more than once.

Image showing a black-lined square grid with the numbers 0, 1, 2 across the top and 0, 1, 2, and 3 going down on the outside of the grid.  The word North and showing to the left of the grid with a black arrow pointing upward. The letter S is shown in the lower right-hand column box of the grid and five black arrows are shown in different grid boxes.

Input

Prompt for and read the number of rows and columns in the grid of rooms for the museum. These will be positive integers separated by a space. Both will be greater than 1. Prompt for and read the starting room. These will be two positive integers, or zero, separated by a space. Prompt for and read a combination of zeros, ones, and twos separated by a space and terminated with 99. The 99 terminates the input and is not an instruction for moving through the museum. There will be at least one instruction but there is no maximum number of instructions. Data will be entered from console. You do not need to edit the input data. Rerun your application to test each test case.

Output

Display a single line on the console indicating the result of the tour. There are four possibilities: successful tour; visited same room more than once; tour ended before leaving museum; left building before tour was over.

Test Data

InputOutput
Enter number of rows then columns:
4 3
Enter starting room (row then column):
0 2
Enter instructions:
0 0 0 1 0 1 1 2 0 0 99
successful tour
Enter number of rows then columns:
4 3
Enter starting room (row then column):
0 1
Enter instructions:
2 0 1 2 99
left building before tour was over
Enter number of rows then columns:
5 6
Enter starting room (row then column):
0 2
Enter instructions:
0 1 0 2 0 2 0 0 99
tour ended before leaving building
Enter number of rows then columns:
8 4
Enter starting room (row then column):
2 2
Enter instructions:
0 2 2 2 0 1 99
visited same room more than once

Additional Information:

  1. You do not need to handle exceptions.
  2. Add your name as a comment in the first line in your source code. Add the following after your name: “Gold #8”.
  3. The judges will test your application with a different set of data that will have a different number of test cases.

Contact

Marwan Shaban
Program Manager
Phone: 407.708.2093
Fax: 407.708.2322
Office: V102-D