Each player in a tournament plays six games. There are no ties. The tournament director places the players in groups based on the results of games as follows:
if a player wins 5 or 6 games, they are placed in Group 1;
if a player wins 3 or 4 games, they are placed in Group 2;
if a player wins 1 or 2 games, they are placed in Group 3;
if a player does not win any games, they are eliminated from the tournament.
Write a program to determine which group a player is placed in.
The input consists of six lines, each with one of two possible
letters: W
(to indicate a win) or
L
(to indicate a loss).
The output will be either 1
,
2
, 3
(to indicate
which Group the player should be placed in) or
-1
(to indicate the player has been
eliminated).
W
L
W
W
L
W
2
L
L
L
L
L
L
-1
Magic Squares are square arrays of numbers that have the interesting property that the numbers in each column, and in each row, all add up to the same total.
Given a \(4\times 4\) square of numbers, determine if it is magic square.
The input consists of four lines, each line having 4 space-separated integers.
Output either magic
if the input is a magic
square, or not magic
if the input is not a
magic square.
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
magic
Notice that each row adds up to 34, and each column also adds up to 34.
5 10 1 3
10 4 2 3
1 2 8 5
3 3 5 0
not magic
Notice that the top row adds up to 19, but the rightmost column adds up to 11.
A palindrome is a word which is the same when
read forwards as it is when read backwards. For example,
mom
and anna
are two
palindromes.
A word which has just one letter, such as
a
, is also a palindrome.
Given a word, what is the longest palindrome that is contained in the word? That is, what is the longest palindrome that we can obtain, if we are allowed to delete characters from the beginning and/or the end of the string?
The input will consist of one line, containing a sequence of at least 1 and at most 40 lowercase letters.
Output the total number of letters of the longest palindrome contained in the input word.
banana
5
The palindrome anana
has 5 letters.
abracadabra
3
The palindromes aca
and
ada
have 3 letters, and there are no other
palindromes in the input which are longer.
abba
4
Fiona commutes to work each day. If there is no rush-hour traffic, her commute time is 2 hours. However, there is often rush-hour traffic. Specifically, rush-hour traffic occurs from 07:00 (7am) until 10:00 (10am) in the morning and 15:00 (3pm) until 19:00 (7pm) in the afternoon. During rush-hour traffic, her speed is reduced by half.
She leaves either on the hour (at XX:00), 20 minutes past the hour (at XX:20), or 40 minutes past the hour (at XX:40).
Given Fiona’s departure time, at what time does she arrive at work?
The input will be one line, which contains an expression of the form
HH:MM
, where HH
is
one of the 24 starting hours (00, 01, \(\ldots\), 23) and
MM
is one of the three possible departure
minute times (00, 20, 40).
Output the time of Fiona’s arrival, in the form
HH:MM
.
05:00
07:00
Fiona does not encounter any rush-hour traffic, and leaving at 5am, she arrives at exactly 7am.
07:00
10:30
Fiona drives for 3 hours in rush-hour traffic, but only travels as far as she normally would after driving for 1.5 hours. During the final 30 minutes (0.5 hours) she is driving in non-rush-hour traffic.
23:20
01:20
Fiona leaves at 11:20pm, and with non-rush-hour traffic, it takes two hours to travel, so she arrives at 1:20am the next day.
Since time immemorial, the citizens of Dmojistan and Pegland have been at war. Now, they have finally signed a truce. They have decided to participate in a tandem bicycle ride to celebrate the truce. There are \(N\) citizens from each country. They must be assigned to pairs so that each pair contains one person from Dmojistan and one person from Pegland.
Each citizen has a cycling speed. In a pair, the fastest person will always operate the tandem bicycle while the slower person simply enjoys the ride. In other words, if the members of a pair have speeds \(a\) and \(b\), then the bike speed of the pair is \(\max(a,b)\). The total speed is the sum of the \(N\) individual bike speeds.
For this problem, in each test case, you will be asked to answer one of two questions:
Question 1: what is the minimum total speed, out of all possible assignments into pairs?
Question 2: what is the maximum total speed, out of all possible assignments into pairs?
The first line will contain the type of question you are to solve, which is either \(1\) or \(2\).
The second line contains \(N\) (\(1 \leq N \leq 100\)).
The third line contains \(N\) space-separated integers: the speeds of the citizens of Dmojistan.
The fourth line contains \(N\) space-separated integers: the speeds of the citizens of Pegland.
Each person’s speed will be an integer between \(1\) and \(1\ 000\ 000\).
For 8 of the 15 available marks, questions of type \(1\) will be asked. For 7 of the 15 available marks, questions of type \(2\) will be asked.
Output the maximum or minimum total speed that answers the question asked.
1
3
5 1 4
6 2 4
12
There is a unique optimal solution:
Pair the citizen from Dmojistan with speed 5 and the citizen from Pegland with speed 6.
Pair the citizen from Dmojistan with speed 1 and the citizen from Pegland with speed 2.
Pair the citizen from Dmojistan with speed 4 and the citizen from Pegland with speed 4.
2
3
5 1 4
6 2 4
15
There are multiple possible optimal solutions. Here is one optimal solution:
Pair the citizen from Dmojistan with speed 5 and the citizen from Pegland with speed 2.
Pair the citizen from Dmojistan with speed 1 and the citizen from Pegland with speed 6.
Pair the citizen from Dmojistan with speed 4 and the citizen from Pegland with speed 4.
2
5
202 177 189 589 102
17 78 1 496 540
2016
There are multiple possible optimal solutions. Here is one optimal solution:
Pair the citizen from Dmojistan with speed 202 and the citizen from Pegland with speed 1.
Pair the citizen from Dmojistan with speed 177 and the citizen from Pegland with speed 540.
Pair the citizen from Dmojistan with speed 189 and the citizen from Pegland with speed 17.
Pair the citizen from Dmojistan with speed 589 and the citizen from Pegland with speed 78.
Pair the citizen from Dmojistan with speed 102 and the citizen from Pegland with speed 496.
This sum yields \(202+540+189+589+496=2016\).