Está en la página 1de 6

Problem Statement

In soccer leagues, the winner of a match is awarded with 3 points and the loser 0 points. In case
of a tie, both teams are awarded with 1 point each.
Create a class Soccer containing the method maxPoints which takes a int[] wins, the number of
wins for each team in the league, and a int[] ties, the number of ties for each team in the
league and returns an int, the maximum points a team in the league has. The i'th elements of wins
and ties correspond to the number of wins and ties respectively for team i.

Definition
Class: Soccer
Method: maxPoints
Parameters: int[], int[]
Returns: int
Method signature: int maxPoints(int[] wins, int[] ties)
(be sure your method is public)

Notes
- Two or more teams may have the same number of points.

Constraints
- wins will contain between 1 and 50 elements, inclusive.
- ties will contain between 1 and 50 elements, inclusive.
- wins will contain the same number of elements as ties.
- Each element in wins will be between 0 and 100, inclusive.
- Each element in ties will be between 0 and 100, inclusive.

Examples
0)
{1,4,3,0,0}
{3,1,5,3,1}
Returns: 14
The number of points for each team are:
Team 0: 3*1 + 1*3 = 6 points
Team 1: 3*4 + 1*1 = 13 points
Team 2: 3*3 + 1*5 = 14 points
Team 3: 3*0 + 1*3 = 3 points
Team 4: 3*0 + 1*1 = 1 point
So team 2 has the most number of points, 14. The method should thus return 14.
1)
{12,45,20,17,48,0}
{48,10,53,94,0,100}
Returns: 145
Both team 1 and team 3 got 145 points, which is the maximum.
2)
{35,0}
{0,76}
Returns: 105
3)
{0,0,0,0}
{0,0,0,0}
Returns: 0
4)
{13,79,26,73,14,89,71,37,89,71,19,59,39}
{88,27,5,70,84,94,20,50,2,11,31,22,50}
Returns: 361

Problem Statement

Problem Statement for MedianOfNumbers

Problem Statement
In a set of distinct numbers, the median is an element M such that the number of elements greater
than M is equal to the number of elements smaller than M. For example, in a set {1, 4, 2, 5, 7}
the median is 4 because two elements (5 and 7) are greater than 4 and 2 elements (1 and 2)
smaller than 4. The set {1, 5, 8, 3} has no median because no element from it satisfies the
definition above.
You are given a int[] numbers. Return the median of numbers or -1 if numbers has no median.

Definition
Class: MedianOfNumbers
Method: findMedian
Parameters: int[]
Returns: int
Method signature: int findMedian(int[] numbers)
(be sure your method is public)

Constraints
- numbers will contain between 1 and 50 elements, inclusive.
- Each element of numbers will be between 1 and 100, inclusive.
- All elements of numbers will be distinct.

Examples
0)
{1, 4, 2, 5, 7}
Returns: 4
The example from the statement.
1)
{1, 5, 8, 3}
Returns: -1
2)
{7}
Returns: 7
There are zero elements that are greater than 7 and zero elements that are smaller than 7.
3)
{7, 12}
Returns: -1
4)
{66, 53, 47, 86, 18, 21, 97, 92, 15}
Returns: 53
5)
{32, 54, 27, 4, 69, 96, 73, 1, 100, 15, 21}
Returns: 32

Problem Statement for AverageCandyLifetime

Problem Statement
On January 1, 2007, a confectioner made several candies.
On the last day of each month she allows her children to eat several of those candies.
The lifetime of a candy is the number of days between January 1 and the day the candy is eaten,
inclusive. For example, the lifetime of a candy eaten on January 31 is 31, and the lifetime of a
candy eaten on December 31 is 365 (note that 2007 wasn't a leap year).
You are given a int[] eatenCandies, the i-th element of which is the number of candies eaten on
the last day of the i-th month of 2007 (January is month 0, February is month 1, etc.). Return
the average lifetime of the candies.

Definition
Class: AverageCandyLifetime
Method: getAverage
Parameters: int[]
Returns: double
Method signature: double getAverage(int[] eatenCandies)
(be sure your method is public)

Notes
- The year 2007 was not a leap year.
- The number of days in the months of 2007, in order, were 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
30 and 31.
- The returned value must be accurate to within a relative or absolute value of 1E-9.

Constraints
- eatenCandies will contain exactly 12 elements.
- Each element of eatenCandies will be between 0 and 1000, inclusive.
- The sum of all the elements in eatenCandies will be greater than 0.

Examples
0)
{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Returns: 60.5
One candy was eaten on January 31 and the other was eaten on March 31. The lifetimes of the
candies are 31 and 31+28+31=90. The average lifetime is (31+90)/2=60.5.
1)
{0, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Returns: 59.0
All candies were eaten on February 28. The lifetime of each candy is 31+28=59, so the average
candy lifetime is 59.0.
2)
{0, 0, 0, 0, 0, 1, 0, 0, 0, 50, 0, 0}
Returns: 301.5882352941176
Most of the candies were eaten on October 31 (Halloween), and the lifetime of each of those
candies is 304. The average lifetime is smaller than 304, because of a candy with lifetime 181,
eaten on June 30.
3)
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
Returns: 252.80769230769232

Problem Statement
You are playing TopRPG, the latest and hottest new console-style RPG (role-playing game) to hit
the market. Much like many RPGs, it features the main characters getting stronger as the game
progresses by obtaining a nebulous sort of thing known as experience, which is typically acquired
by killing monsters.
The strategy guide open in front of you tells you how much experience you'll need to get to each
level, represented as a int[] expNeeded. For example, if expNeeded were {150, 450, 900, 1800},
you would need a total of 150 experience to get to level 1 (from level 0), then another (450 -
150) = 300 experience to get to level 2, and so on.
You have 0 experience at the start, and you are about to go through an area where you will get a
fixed amount of experience. You want to know how far you will be from the next level after you
finish. Given a int[] expNeeded, where the ith element is the total amount of experience required
to advance to level i, and an int received, indicating the amount of experience you will get,
return an int which is the amount of experience it will take you to get to the next level after
you receive the experience.

Definition
Class: LevelUp
Method: toNextLevel
Parameters: int[], int
Returns: int
Method signature: int toNextLevel(int[] expNeeded, int received)
(be sure your method is public)

Constraints
- expNeeded will contain between 1 and 50 elements, inclusive.
- Each element in expNeeded will be greater than all elements with lower indices.
- All elements in expNeeded will be between 1 and 999999, inclusive.
- received will be between 0, inclusive, and the largest element of expNeeded, exclusive.

Examples
0)
{150,450,900,1800}
133
Returns: 17
You receive 133 experience, which isn't enough to get to level 1. You need is 150 - 133 = 17
more to get there.
1)
{150,450,900,1800}
312
Returns: 138
With the same situation, you now receive 312 experience. The first 150 advances you to level 1.
There is 162 left, which then goes to the 450 - 150 = 300 experience you need to get from level
1 to level 2. Thus to get to the next level (2), you need 300 - 162 = 138 more experience.
2)
{150,450,900,1800}
612
Returns: 288
3)
{150,450,900,1800}
450
Returns: 450
You advance exactly to level 2, and thus need 900 - 450 = 450 experience to get to the next
level.

Problem Statement for InsideOut

Problem Statement
Your printer has been infected by a virus and is printing gibberish. After staring at several
printed pages for a while, you realize that it is printing every line inside-out. In other words,
the left half of each line is being printed starting in the middle of the page and proceeding out
toward the left margin. Similarly, the right half of each line is being printed starting at the
right margin and proceeding in toward the middle of the page. For example, the line
THIS LINE IS GIBBERISH
is being printed as
I ENIL SIHTHSIREBBIG S
Your task is to unscramble a String line from its printed form back into its original order. You
can assume that line contains an even number of characters.

Definition
Class: InsideOut
Method: unscramble
Parameters: String
Returns: String
Method signature: String unscramble(String line)
(be sure your method is public)

Constraints
- line contains between 2 and 50 characters, inclusive.
- line contains an even number of characters.
- line contains only uppercase letters ('A'-'Z') and spaces (' ').

Examples
0)
"I ENIL SIHTHSIREBBIG S"
Returns: "THIS LINE IS GIBBERISH"
The example above.
1)
"LEVELKAYAK"
Returns: "LEVELKAYAK"
2)
"H YPPAHSYADILO"
Returns: "HAPPY HOLIDAYS"
3)
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Returns: "MLKJIHGFEDCBAZYXWVUTSRQPON"
4)
"RUT OWT SNEH HCNERF EERHTEGDIRTRAP A DNA SEVODELT"
Returns: "THREE FRENCH HENS TWO TURTLEDOVES AND A PARTRIDGE"

También podría gustarte