Input and Output Sample Input Sample Output

1. Fibinary Numbers
The standard interpretation of the binary number 1010 is 8 + 2 = 10. An
alternate way to view the sequence 1010 is to use Fibonacci numbers as bases
instead of powers of two. For this problem, the terms of the Fibonacci sequence
are:
1, 2, 3, 5, 8, 13, 21, ...
Where
one 1
could
1x5 +
each term is the sum of the two preceding terms (note that there is only
in the sequence as defined here). Using this scheme, the sequence 1010
be interpreted as
0x3 + 1x2 + 0x1 = 7. This representation is called a Fibinary number.
Note that there is not always a unique Fibinary representation of every number.
For example the number 10 could be represented as either 8 + 2 (10010) or as 5
+ 3 + 2 (1110). To make the Fibinary representations unique, larger Fibonacci
terms must always be used whenever possible (i.e. disallow 2 adjacent 1's).
Applying this rule to the number 10, means that 10 would be represented as 8+2
(10010).
Input and Output
Write a program that takes two valid Fibinary numbers and prints the sum in
Fibinary form. These numbers will have at most 100 digits.
In case that two or more test cases had to be solved, it must be a blank line
between two consecutive, both in input and output files.
Sample Input
10010
1
10000
1000
Sample Output
10100
100000
2. The "Paren" Thesis
Jane Paren, was sitting around the house one day thinking about a multiplication
machine she wanted to design. Her machine would take an ordered sequence of
variables or numbers, like this:
X1, X2, X3, X4, …, XN
And then determine all possible ordered, multiplicative "groupings" of the
objects like this:
(X1(X2(X3(X4(...(XN-1*XN)...)))))
. . .
. . .
. . .
. . .
. . .
. . .
(((...(((X1*X2)X3)X4)...)XN-1)XN)
Jane hypothesized that a machine could produce these different groupings by
repeatedly dividing the main sequence into two parts starting on the left and
working toward the right, and then treating each of these sub-sequences just
like the main sequence was treated. The very first division into two subsequences is shown here:
(X1)(X2X3...XN-1XN))
Later in the sequence another division of the main sequence into two subsequences is shown below:
((X1X2X3...Xj-1)(Xj...XN-1XN))
Both the left and right sequences must be subdivided from left to right just
like the main sequence. You will help Jane Paren verify her hypothesis by
writing a program that can group a sequence into a series of multiplications
using parentheses. Your program will not perform the actual multiplications; it
will only find and output all possible ordered parenthesized groupings in the
order specified by Jane's hypothesis.
Input
The input will consist of multiple lines of variable names or numbers.
Each variable name or number will be separated from its neighbors by spaces.
The input line will be terminated by carriage-return/line-feed (standard end-ofline marker).
Ignore multiple blank lines in the input and treat them as a single blank line.
The program will stop reading input when it reaches the end of the file.
Output
For each input line, the program will generate all possible multiplicative
groupings, keeping the numbers or variables from the input line in their
original order. The order in which the multiplicative groupings are output does
matter!
Subsequences consisting of just one element will not have its' own set of
parenthesis.
Subsequences consisting
multiplication symbol *
e.g. (x*y)
For each element of the
output will display the
within the group.
of just two elements are separated with the
and have a set of parenthesis around them in the output,
set of outputs calculated from a given input line, the
line from which the group originated and the number
Outputs must conform to the same formatting as the sample output, including
spaces!
Separate each set of output groupings by a blank line.
Sample Input
1 2
North South East West
Sample Output
Input Line 1 Group 1. (1*2)
Input
Input
Input
Input
Input
Line
Line
Line
Line
Line
2
2
2
2
2
Group
Group
Group
Group
Group
1.
2.
3.
4.
5.
(North(South(East*West)))
(North((South*East)West))
((North*South)(East*West))
((North(South*East))West)
(((North*South)East)West)
3. Bejmul (Jumble)
Most of you are probably familiar with Jumble, a daily newspaper feature, where
you reconstruct scrambled words. For example, you might be given `ROYIN' and
have to come up with `IRONY'.
One aspect that makes a particular scrambling of letters ``hard" is if it looks
like a ``real" word. Thus, `ROYIN' is tougher scramble than `NRYIO' because it
confuses your brain into thinking that it's already a word.
Another aspect that makes a scrambling harder is whether letters are in their
correct position. So, `RIONY' isn't a very good scramble, even if it might kindof look like a real word.
Your task is to write a program that scores scrambles as `good', `fair', `poor',
or `not'. Your program will read pairs of words and score them. A scramble is
`good' if none of its letters are in the correct place and it looks ``real"
(more on that later). A scramble is `poor' if it doesn't look ``real" and has
either the first letter in place or any two consecutive letters in place. If the
word isn't scrambled at all, it is said to be `not' scrambled. Otherwise, the
scramble is ``fair".
How do we know if a word looks "real"? We will use an extremely crude heuristic
that the word must alternate between vowels (`Y' is a vowel for these purposes)
and consonants. However, certain groups of vowels and consonants are allowed:
AI
BL
KL
SK
TW
AY
BR
KR
SL
WH
EA
CH
KW
SM
WR
EE
CK
PF
SN
EO
CL
PL
SP
IO
CR
PR
SQ
OA
DR
SC
ST
OO OY YA YO YU
FL FR GH GL GR
SCH SCR SH SHR
SW TH THR TR
Also, all double consonants are allowed. No other combinations are allowed, so
`SWR' wouldn't be good, even though both `SW' and `WR' are both OK.
DUCK GOLO! (That's a scramble of `GOOD LUCK'!)
Input
The input for your program will be pairs of words, all upper-case letters,
alternating until a ``word" of `999' is encountered. The first word of the pair
is the original word; the second is the scrambled version that you must
evaluate. You may assume that the words are anagrams of one another and contain
no spaces. Words will be at least 3 letters in length.
Output
For each pair, you should print how well the second scores as a scramble of the
first. Use the format shown in the sample.
Sample Input
SPAM
MAPS
IRONY
RIONY
IRONY
ONYRI
IRONY
IRONY
999
Sample Output
"MAPS" is a fair scramble of "SPAM"
"RIONY" is a fair scramble of "IRONY"
"ONYRI" is a good scramble of "IRONY"
"IRONY" is not a scramble of "IRONY"
4. The Cubic End
Given any string of decimal digits, ending in 1, 3, 7 or 9, there is always a
decimal number, which when cubed has a decimal expansion ending in the original
given digit string. The number need never have more digits than the given digit
string.
Write a program, which takes as input a string of decimal digits ending in 1, 3,
7 or 9 and finds a number of at most the same number of digits, which when
cubed, ends in the given digit string.
Input
The input begins with a line containing only the count of problem instances,
nProb, as a decimal integer, 1 nProb 1000 . This is followed by nProb lines,
each of which contains a string of between 1 and 10 decimal digits ending in 1,
3, 7 or 9.
Output
For each problem instance, there should be one line of output consisting of the
number, which when cubed, ends in the given digit string. The number should be
output as a decimal integer with no leading spaces and no leading zeroes.
Sample Input
3
123
1234567
435621
Sample Output
947
2835223
786941
5. Guardian of Decency
Frank N. Stein is a very conservative high-school teacher. He wants to take some
of his students on an excursion, but he is afraid that some of them might become
couples. While you can never exclude this possibility, he has made some rules
that he thinks indicates a low probability two persons will become a couple:
•
•
•
•
Their height differs by more than 40 cm.
They are of the same sex.
Their preferred music style is different.
Their favourite sport is the same (they are likely to be fans of different
teams and that would result in fighting).
So, for any two persons that he brings on the excursion, they must satisfy at
least one of the requirements above. Help him find the maximum number of persons
he can take, given their vital information.
Input
The first line of the input consists of
test cases. The first line of each test
giving the number of pupils. Next there
consisting of four space-separated data
•
•
•
•
an integer T ≤ 100 giving the number of
case consists of an integer N ≤ 500
will be one line for each pupil
items:
an integer h giving the height in cm;
a character 'F' for female or 'M' for male;
a string describing the preferred music style;
a string with the name of the favourite sport.
No string in the input will contain more than 100 characters, nor will any
string contain any whitespace.
Output
For each test case in the input there should be one line with an integer giving
the maximum number of eligible pupils.
Sample Input
1
4
35 M classicism programming
0 M baroque skiing
43 M baroque chess
30 F baroque soccer
Sample Output
3
6. Stacking Cylinders
Cylinders (e.g. oil drums) (of radius 1 foot) are stacked in a rectangular bin.
Each cylinder on an upper row rests on two cylinders in the row below. The
cylinders in the bottom row rest on the floor. Each row has one less cylinder
than the row below.
This problem is to write a program to compute the location of the center of the
top cylinder from the centers of the cylinders on the bottom row. Computations
of intermediate values should use double precision.
Input
Each data set will appear in one line of the input in the file. An input line
consists of the number, n, of cylinders on the bottom row followed by n floating
point values giving the x coordinates of the centers of the cylinders (the y
coordinates are all 1.0 since the cylinders are resting on the floor (y = 0.0)).
The value of n will be between 1 and 10 (inclusive). The end of input is
signaled by a value of n = 0. The distance between adjacent centers will be at
least 2.0 (so the cylinders do not overlap) but no more than 3.4 (cylinders at
level k will never touch cylinders at level k - 2).
Output
The output for each data set is a line containing the x coordinate of the
topmost cylinder rounded to 4 decimal places, a space and the y coordinate of
the topmost cylinder to 4 decimal places.
Note: To help you check your work, the x-coordinate of the center of the top
cylinder should be the average of the x-coordinates of the leftmost and
rightmost bottom cylinders
Sample Input
4 1.0 4.4 7.8 11.2
1 1.0
6 1.0 3.0 5.0 7.0 9.0 11.0
0
Sample Output
6.1000 4.1607
1.0000 1.0000
6.0000 9.6603
7. Fast Food
The fastfood chain McBurger owns several restaurants along a highway. Recently,
they have decided to build several depots along the highway, each one located at
a restaurent and supplying several of the restaurants with the needed
ingredients. Naturally, these depots should be placed so that the average
distance between a restaurant and its assigned depot is minimized. You are to
write a program that computes the optimal positions and assignments of the
depots.
To make this more precise, the management of McBurger has issued the following
specification: You will be given the positions of n restaurants along the
highway as n integers
(these are the distances measured from
the company's headquarter, which happens to be at the same highway).
Furthermore, a number
will be given, the number of depots to be built.
The k depots will be built at the locations of k different restaurants. Each
restaurant will be assigned to the closest depot, from which it will then
receive its supplies. To minimize shipping costs, the total distance sum,
defined as:
must be as small as possible.
Write a program that computes the positions of the k depots, such that the total
distance sum is minimized.
Input
The input file contains several descriptions of fastfood chains. Each
description starts with a line containing the two integers n and k. n and k will
satisfy
,
,
. Following this will n lines
containing one integer each, giving the positions di of the restaurants, ordered
increasingly.
The input file will end with a case starting with n = k = 0. This case should
not be processed.
Output
For each chain, first output the number of the chain. Then output an optimal
placement of the depots as follows: for each depot output a line containing its
position and the range of restaurants it serves. If there is more than one
optimal solution, output any of them. After the depot descriptions output a line
containing the total distance sum, as defined in the problem text.
Output a blank line after each test case.
Sample Input
6 3
5
6
12
19
20
27
0 0
Sample Output
Chain
Depot
Depot
Depot
Total
1
1 at restaurant 2 serves restaurants 1 to 3
2 at restaurant 4 serves restaurants 4 to 5
3 at restaurant 6 serves restaurant 6
distance sum = 8
8. Digital Roots
The digital root of a positive integer is found by summing the digits of the
integer. If the resulting value is a single digit then that digit is the digital
root. If the resulting value contains two or more digits, those digits are
summed and the process is repeated. This is continued as long as necessary to
obtain a single digit.
For example, consider the positive integer 24. Adding the 2 and the 4 yields a
value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now,
consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is
not a single digit, the process must be repeated. Adding the 1 and the 2 yields
3, a single digit and also the digital root of 39.
Input
The input file will contain a list of positive integers, one per line. The end
of the input will be indicated by an integer value of 0.
Output
For each integer in the input, output its digital root on a separate line of the
output.
Sample Input
24
39
0
Sample Output
6
3