You record all of the scoring activity at a basketball game. Points are scored by a 3-point shot, a 2-point field goal, or a 1-point free throw.
You know the number of each of these types of scoring for the two teams: the Apples and the Bananas. Your job is to determine which team won, or if the game ended in a tie.
The first three lines of input describe the scoring of the Apples, and the next three lines of input describe the scoring of the Bananas. For each team, the first line contains the number of successful 3-point shots, the second line contains the number of successful 2-point field goals, and the third line contains the number of successful 1-point free throws. Each number will be an integer between 0 and 100, inclusive.
The output will be a single character. If the Apples scored more points
than the Bananas, output A
. If the Bananas
scored more points than the Apples, output B
.
Otherwise, output T
, to indicate a tie.
10
3
7
8
9
6
B
The Apples scored
7
3
0
6
4
1
T
The Apples scored
You and your friend have come up with a way to send messages back and forth.
Your friend can encode a message to you by writing down a positive
integer
Given a message that your friend has encoded, decode it.
The first line of input contains
The next
The output should be N x
, then line x
printed
N
times.
4
9 +
3 -
12 A
2 X
+++++++++
---
AAAAAAAAAAAA
XX
Your new cellphone plan charges you for every character you send from your phone. Since you tend to send sequences of symbols in your messages, you have come up with the following compression technique: for each symbol, write down the number of times it appears consecutively, followed by the symbol itself. This compression technique is called run-length encoding.
More formally, a block is a substring of identical symbols that is as long as possible. A block will be represented in compressed form as the length of the block followed by the symbol in that block. The encoding of a string is the representation of each block in the string in the order in which they appear in the string.
Given a sequence of characters, write a program to encode them in this format.
The first line of input contains the number
Output will be
4
+++===!!!!
777777......TTTTTTTTTTTT
(AABBC)
3.1415555
3 + 3 = 4 !
6 7 6 . 12 T
1 ( 2 A 2 B 1 C 1 )
1 3 1 . 1 1 1 4 1 1 4 5
To see how the first message (on the second line of input) is encoded,
notice that there are 3 +
symbols, followed by
3 =
symbols, followed by 4
!
symbols.
You are trying to pass the time while at the optometrist. You notice there is a grid of four numbers:
1 | 2 |
3 | 4 |
You see lots of mirrors and lenses at the optometrist, and wonder how flipping the grid horizontally or vertically would change the grid.
Specifically, a “horizontal” flip (across the horizontal centre line) would take the original grid of four numbers and result in:
3 | 4 |
1 | 2 |
A “vertical” flip (across the vertical centre line) would take the original grid of four numbers and result in:
2 | 1 |
4 | 3 |
Your task is to determine the final orientation of the numbers in the grid after a sequence of horizontal and vertical flips.
The input consists of one line, composed of a sequence of at least one
and at most 1 000 000 characters. Each character is either
H
, representing a horizontal flip, or
V
, representing a vertical flip.
For 8 of the 15 available marks, there will be at most 1 000 characters in the input.
Output the final orientation of the four numbers. Specifically, each of the two lines of output will contain two integers, separated by one space.
HV
4 3
2 1
VVHH
1 2
3 4
A substitution rule describes how to take a
sequence of symbols and convert it into a different sequence of symbols.
For example, ABA
In this task, you will be given three substitution rules, a starting sequence of symbols and a final sequence of symbols. You are to use the substitution rules to convert the starting sequence into the final sequence, using a specified number of substitutions.
For example, if the three substitution rules were:
AA
AB
B
we could convert the sequence AB into AAAB in 4 steps, by the following substitutions:
where the symbols to be replaced are shown in bold. More specifically, from the initial sequence AB, substitute rule 2 starting at position 1, to get the result BB. From BB, substitute rule 3, starting at position 1, to get the result AAB. From AAB, substitute rule 3, starting at position 3, to get the result AAAA. From AAAA, substitute rule 1, starting at position 3, to get the result AAAB, which is the final sequence.
The first three lines will contain the substitution rules. Each
substitution rule will be a sequence of A
’s
and B
’s, followed by a space following by
another sequence of A
’s and
B
’s. Both sequences will have between one and
five symbols.
The next line contains three space separated values, A
’s and
B
’s, where there are at least one and at most
5 symbols in
For 7 of the 15 marks available,
For an additional 7 of the 15 available marks,
The output will be
Line
1
, 2
or 3
) that will be used.
There will always be at least one sequence of
AA AB
AB BB
B AA
4 AB AAAB
2 1 BB
3 1 AAB
3 3 AAAA
1 3 AAAB
This is the example outlined in the problem description. Note that the following is another possible valid substitution sequence:
2 1 BB
3 2 BAA
1 2 BAB
3 1 AAAB
Specifically, showing the substitutions in bold, we get