Here at the Concerned Citizens of Commerce (CCC), we have noted that telemarketers like to use seven-digit phone numbers where the last four digits have three properties. Looking just at the last four digits, these properties are:
the first of these four digits is an 8 or 9;
the last digit is an 8 or 9;
the second and third digits are the same.
For example, if the last four digits of the telephone number are 8229, 8338, or 9008, these are telemarketer numbers.
Write a program to decide if a telephone number is a telemarketer number or not, based on the last four digits. If the number is not a telemarketer number, we should answer the phone, and otherwise, we should ignore it.
The input will be 4 lines where each line contains exactly one digit in
the range from
Output either ignore
if the number matches the
pattern for a telemarketer number; otherwise, output
answer
.
9
6
6
8
ignore
The first digit is
5
6
6
8
answer
The first digit is
You supervise a small parking lot which has
Yesterday, you recorded which parking spaces were occupied by cars and which were empty.
Today, you recorded the same information.
How many of the parking spaces were occupied both yesterday and today?
The first line of input contains the integer C
to indicate an occupied space
or .
to indicate it was an empty parking
space.
Output the number of parking spaces which were occupied yesterday and today.
5
CC..C
.CC..
1
Only the second parking space from the left was occupied yesterday and today.
7
CCCCCCC
C.C.C.C
4
The first, third, fifth, and seventh parking spaces were occupied yesterday and today.
You decide to go for a very long drive on a very straight road. Along this road are five cities. As you travel, you record the distance between each pair of consecutive cities.
You would like to calculate a distance table that indicates the distance between any two of the cities you have encountered.
The first line contains 4 positive integers less than 1000, each
representing the distances between consecutive pairs of consecutive
cities: specifically, the
The output should be
3 10 12 5
0 3 13 25 30
3 0 10 22 27
13 10 0 12 17
25 22 12 0 5
30 27 17 5 0
The first line of output contains:
Barbara plants
She records each of these measurements in a table, with one row for each plant, with the first row recording the shortest sunflower’s growth and the last row recording the tallest sunflower’s growth. The leftmost column is the first measurement for each sunflower, and the rightmost column is the last measurement for each sunflower.
If a sunflower was smaller than another when initially planted, it remains smaller for every measurement.
Unfortunately, her children may have altered her measurements by rotating her table by a multiple of 90 degrees.
Your job is to help Barbara determine her original data.
The first line of input contains the number
Output Barbara’s original data, consisting of
2
1 3
2 9
1 3
2 9
The data has been rotated a multiple of 360 degrees, meaning that the input arrangement is the original arrangement.
3
4 3 1
6 5 2
9 7 3
1 2 3
3 5 7
4 6 9
The original data was rotated 90 degrees to the right/clockwise.
3
3 7 9
2 5 6
1 3 4
1 2 3
3 5 7
4 6 9
The original data was rotated 90 degrees to the left/counter-clockwise.
There is a genre of fiction called choose your own adventure books. These books allow the reader to make choices for the characters which altersthe outcome of the story.
For example, after reading the first page of a book, the reader may be asked a choice, such as “Do you pick up the rock?” If the reader answers “yes”, they are directed to continue reading on page 47, and if they choose “no”, they are directed to continue reading on page 18. On each of those pages, they have further choices, and so on, throughout the book. Some pages do not have any choices, and thus these are the “ending” pages of that version of the story. There may be many such ending pages in the book, some of which are good (e.g., the hero finds treasure) and others which are not (e.g., the hero finds a leftover sandwich from 2001).
You are the editor of one of these books, and you must examine two features of the choose your own adventure book:
ensure that every page can be reached – otherwise, there is no reason to pay to print a page which no one can ever read;
find the shortest path, so that readers will know what the shortest amount of time they need to finish one version of the story.
Given a description of the book, examine these two features.
The first line of input contains
If
Note that you always begin the book on page 1.
For 4 of the available 15 marks,
For an additional 3 of the available 15 marks, the book is guaranteed to have no cycles.
For an additional 4 of the available 15 marks,
The output will be two lines. The first line will contain
Y
if all pages are reachable, and
N
otherwise. The last line will contain a
non-negative integer
3
2 2 3
0
0
Y
2
Since we start on page 1, and can reach both page 2 and page 3, all
pages are reachable. The only paths in the book are
3
2 2 3
0
1 1
Y
2
Every page is reachable, since from page 1, we can reach pages 2 and 3.
The shortest path is the path 1