A number squared is defined as the number multiplied by itself. In this problem, given a number n, print the number $$$n^{2}$$$.
The only line of input contains a positive integer n.
Print the number $$$n^{2}$$$: n multiplied by itself.
6
36
Basic math operations are very important in programming applications. In this problem, your task is to calculate the product of two integers, multiplied by three.
The first line of input contains a positive integer a no greater than 2000. The second line of input contains a positive integer b no greater than 2000.
Print a single positive integer c: the product of a and b multiplied by 3.
3 5
45
Triangles are one of the simplest geometric shapes. Equilateral triangles have the special property of all three of their sides being equal to each other. In this problem, you will be given a list of side lengths of equilateral triangles. You should find the sum of the perimeters of the triangles, given that the triangles are all equilateral.
The first line of the input will contain a positive integer n indicating the number of triangles. Each of the next n lines will contain an integer t, indicating the side length of each triangle.
Print one number, the calculated sum of the perimeters of the triangles.
3 3 4 6
39
In the example, the first triangle has a side length of 3, so it has a perimeter of 9. The second triangle has a perimeter of 12, and the third triangle has a perimeter of 18.
The sum of the angles in a triangle is 180, and the sum of the angles in a square is 360. In fact, the sum of angles in any polygon increases by 180 with each side added to the polygon. In this problem, you must figure out the sum of angles of a polygon, given its number of sides.
The first line of the input contains a positive integer T indicating the number of test cases in the problem. The next T lines each contain a positive integer n (1 <= n <= 100): the number of sides of each polygon.
Output T integers: the sum of the angles in each polygon.
4 3 4 5 6
180 360 540 720
Take in a number from 1 through 1000, print Fizz if the number is divisible by 3, print Buzz if the number is divisible by 5, or FizzBuzz if the number is divisible by both. If none of these conditions are true, print nothing
The only line of input contains a single positive integer N between 1 and 1000 inclusively
Fizz, Buzz, FizzBuzz, or nothing
1
3
Fizz
5
Buzz
15
FizzBuzz
Find the distance between two 2D points. Remember that the distance formula is
$$$d = \sqrt{(x_{2} - x_{1})^2 + (y_{2}-y_{1})^2}$$$
math.sqrt will calculate the square root of a number. Also, you also have to add the line import math at the top of the program.
The first two lines contain the X and Y coordinates of the first point respectively. The second two lines contain the X and Y coordinates of the second point respectively. Each coordinate will have an integer value between -1000 and 1000, inclusive.
A double N representing the distance between the two points
1 1 2 2
1.4142135623730951
1 1 1 1
0.0
You have a clock that tells time in the usual way: hours, minutes, and seconds. When you wake up in the morning, you want to figure out how many seconds you slept for. Conveniently, you fell asleep the night before at exactly 12:00 AM. Remember that there are 60 seconds in a minute and 60 minutes in an hour.
The first line of input contains a positive integer h indicating the current number of hours displayed on the clock (1 <= h <= 11). The second line of input contains a positive integer m indicating the current number of minutes displayed on the clock (0 <= m <= 59) The third line of input contains a positive integer s indicating the current number of seconds displayed on the clock (0 <= s <= 59) The fourth line of input contains a string a indicating whether it is currently the morning or the afternoon. a will be either AM or PM. You are guaranteed to have slept for less than 24 hours. Also, note that h will never equal 12.
Print a single positive integer t: the number of seconds of sleep that you got.
6 50 34 AM
24634
Calculate the distance between two points of a specified dimension. The common distance formula still applies to higher dimensional points with a small modification. You will input two points and display the distance between them as you normally would with the distance formula.
The n-dimensional distance formula can be expressed as
$$$d(p,q) = \sqrt{(q_{1}-p_{1})^2 + (q_{2}-p_{2})^2 + ... + (q_{n}-p_{n})^2}$$$
or in other terms:
$$$\sqrt{\sum_{i=1}^{n} (q_{i}-p_{i})^2} = d$$$
Remember that math.sqrt will calculate the square root of a number (you also have to add the line import math at the top of the program).
The first line contains the dimension D between 2 and 500. Then, D test cases will follow.
Each test case N will consist of two lines: the value of the first point, and the value of the second point, in the Nth dimension.
Each of these values is an integer between -5000 and 5000, inclusive.
A decimal number N representing the distance between the two points. Do not round your answer.
2 1 1 1 2
1.0
3 7 4 3 17 6 2
14.866068747318506
4 -2367 -2873 -4279 -2321 -1302 -1341 -2893 651
4080.5951771769764
A hello world program is an essential starting point for all coders. In this problem, write a program to print out "Hello CodeRams".
In Python, you can print text using the print command. So, for this problem, type print("Hello CodeRams").
You can download Python here.
Output "Hello CodeRams"
there is no input for this problem
Hello CodeRams
Your favorite basketball player is the leading scorer in the country, and you want to know exactly how good they are. Points per game is measured as points divided by games played, and is used to rank leading scorers in basketball.
The first line of input contains a positive integer p indicating the total points scored by the player so far during the season. The second line of input contains a positive integer g indicating the total games played by the player so far during the season.
Output one decimal number ppg, the player's current points per game. This value can be calculated as p / g
78 7
11.142857142857142
89 15
5.933333333333334
Your favorite ski resort has a certain number of easy trails, more difficult trails, most difficult trails, and expert-only trails. Given these values, find how many trails there are at the ski resort. Note that the same trail will never be two different difficulties.
The only line of input contains 4 space-separated integers, each representing the number of easy trails, more difficult trails, most difficult trails, and expert-only trails, respectively.
Print one positive integer: the total number of ski trails at the mountain.
20 16 13 6
55
In the last contest, you were asked to find the last digit of a very large number. This time, you are asked to find the entirety of a much smaller number: your task is to find the first number taken to the power of second number. A brute force approach does work here.
The only line of input contains two space-separated integers n and k, 1 <= n, k <= 10.
Output a single integer: the number $$$n^{k}$$$.
3 5
243
When two resistors with resistances a and b are parallel in an electronic circuit, their equivalent resistance is calculated as (a * b) / (a + b). Given the resistances of two resistors, calculate their equivalent resistance.
The first line of input contains a single positive integer a: the resistance of the first resistor. The second line of input contains a single positive integer b: the resistance of the second resistor.
Output a single positive decimal number r: the equivalent resistance of the two resistors, calculated using the above formula.
60 40
24.0
80 70
37.333333333333336
You find yourself stuck in a labyrinth and don't know your way out! There are several dangerous traps placed throughout the labyrinth. You need to find a way out, but first you need to know how many traps there are in the labyrinth.
You will be 2D grid with dimensions n by m. x denotes a trap, and . denotes no trap. The first line of input will contain two space-separated integers n and m, representing the dimensions of the grid. The next n lines will each contain m characters representing a row of the labyrinth.
Output a single integer t: the total number of traps in the labyrinth.
4 5 x.... .x.x. x..x. x.xx.
8
Hint: use a 2D array!
You're going to a large city with a complex subway system. You need to find out how many subway lines you will take from the airport to your hotel. Given a list of stations that each subway line stops at, print the minimum number of lines you need to take to get from the airport to your hotel.
The first lines contains one integer n, representing the number of different lines in the subway. The next n lines contain an arbitrary number of space-separated strings, each representing the various stations that the subway lines stop at. The airport's station will be Airport in the station list, and the hotel's station will be Hotel. There will not be more than 1000 distinct station names.
Output one positive integer l: the minimal number of different subway lines that you should take to reach the hotel station from the airport station.
4 Airport CityCenter WestStation CityCenter Library EastStation WestStation Countryside Countryside Library Hotel
3
5 Airport TownHall TownHall Courthouse Courthouse WestStation WestStation NorthStation TownHall Hotel
2
A note from the creator of the problem (Xavier): This problem is really hard. I created the problem and it took me over an hour to come up with a valid solution. Please only attempt this problem if you know what you're doing.
While testing your gravity vehicle for Science Olympiad, you have decided to test the vehicle both on Earth, and on Mars. You want to know the gravitational constant of the planet that you are currently testing the vehicle on. You are given that the gravitational constant on Earth is 9.807 m/s^2 and the gravitational constant on Mars is 3.711 m/s^2.
The only line of input contains a single string s: either "EARTH" or "MARS", which indicates the planet that you are currently testing the gravity vehicle on.
Output a single decimal number: the gravitational constant of the planet that you are testing the vehicle on.
EARTH
9.807
MARS
3.711
While preparing for Chemistry Lab in Science Olympiad, you are taught to "cross your charges" when calculating the molecular coefficients given the charges: using the charges of two bonded ions, you swap the two values to obtain the molecular coefficients. For example, a molecule made of two ions with charges of 4 and 3 would have coefficients of 3 and 4, respectively.
The only line of input contains two space-separated integers a and b representing the charges of a and b, respectively.
Output two space-separated integers c and d: the coefficients of each ion given their charges. These can be calculated by swapping a and b (crossing the charges).
2 3
3 2
In mechanical engineering, the primary tool used to measure the energy amplified into a simple machine or a compound machine is called a concept known as the Mechanical Advantage, which signifies the ratio of the energy put into a machine, and the amount of force it outputs.
In one type of simple machine, the lever, mechanical advantage will be calculated by the lengths of the two sides, with the position of the fulcrum determining the length of the two sides. A diagram and a simplified formula of this process has been given below:
Your objective is to find the mechanical advantage of a lever, given side A and side B. The first positive integer n is the amount of inputs that will follow.
4 10 5 2 3 7 5 18 7
2.0 0.6666666666666666 1.4 2.5714285714285716
You are working on your Boomilevers for Science Olympiad, an event that requires the breaking of various "boomilevers". For this problem, you are given a list of numbers representing the force you applied to each boomilever in pounds. You know a certain number of pounds that will always break any boomilever. Given these values, calculate how many of your boomilevers have broken so far.
The first line of input contains two space-separated integers n and m representing the number of boomilevers, and the force required to break a boomilever, respectively. The next line contains n space-separated integers representing the force applied to each boomilever.
Output a single positive integer b: the number of boomilevers that have broken so far.
5 30 20 25 30 35 40
3
Encryption has been an essential tool throughout history and the modern world. Essentially, encryption is the practice of encoding messages, for the purposes of securing the message's confidentiality from other parties.
Your Job is to create a basic encryption method, where if we cast characters of a word to an integer, the odds will be swapped with its following even character, where the first positive integer n are the number of cases following it.
4 ABCDEFG GAME RAMBOOK EHLLO
BADCFEG AGEM ARBMOOK HELLO
(If the word is of an odd length, the last character should be the same)
While testing your hovercraft for Science Olympiad, the hovercraft flew over a pile of boxes in your basement and traveled a total distance of n feet. Given that the boxes are in a rectangular shape, and that the hovercraft took off and landed at opposite corners of the pile of boxes, calculate how far you will have to walk to pick up the hovercraft. You are also given the length of one side of the pile of boxes.
The first line of input contains a single positive integer n: how far the hovercraft traveled in feet. The second line of input contains a single positive integer m: the length of one side of the file of boxes.
Output a single positive integer w: how far you will have to walk to retrieve the hovercraft.
10 6
14.0
14 13
18.196152422706632
Uh oh! You are working on building an analog thermometer using nonlinear components, so how can you calibrate your temperature sensor with test data? You can use a form of nonlinear regression in the form of the Steinhart-Hart equation, an equation designed to explain the relation between the electrical resistance of a solid and its temperature. While this task may sound difficult, it is actually quite simple using the equation. The Steinhart-Hart equation itself has three calculated constants(A,B, and C), and takes in a value R, which is the resistance of the metal.
The equation is represented as:
$$$\frac1T = A + B(lnR) + C(lnR)^3$$$
This equation is useful for the process of actual temperature determination, but we still need to calculate the constants A, B, and C before we can use it. To find these values, we must first find three resistance to temperature data points, which are usually discovered through experimentation. For this problem, these data points will be provided and you will be required to find the A, B, and C constants. The process of finding these values involves calculating a series of equations. These equations are as follows:
$$$L_1 = lnR_1$$$
$$$L_2 = lnR_2$$$
$$$L_3 = lnR_3$$$
$$$Y_1 = \frac{1}{T_1}$$$
$$$Y_2 = \frac{1}{T_2}$$$
$$$Y_3 = \frac{1}{T_3}$$$
$$$\gamma_2 = (Y_2-Y_1)/(L_2-L_1)$$$
$$$\gamma_3 = (Y_3-Y_1)/(L_3-L_1)$$$
$$$C = ((\gamma_3-\gamma_2)/(L_3-L_2))*(L1+L2+L3)^{-1}$$$
$$$B = \gamma_2-C(L_1^2+L_1L_2+L_2^2)$$$
$$$A = Y_1 - L_1(B+L_1^2C)$$$
For this problem, you will be given R1, R2, R3, T1, T2, and T3. You are tasked with then calculating the value for A, you will not have to return B and C considering that a valid number for A will imply correct values for B and C.
The double values T1, T2, T3, R1, R2, and R3 will be each provided sequentially on a separate line.
A double representing the value of A
1 50 100 50000 25000 15000
72.6660018932261
Do not worry about precision or rounding, as there is some tolerance in the solution checking. Also, remember that you can calculate the natural log of a number using math.log in Python or Math.log in Java. In addition, some of the provided equations require variables from previous equations, so you will need to solve them in order.
You are currently working on Ping Pong Parachute for Science Olympiad and you want to test how high your rocket is going. The only problem is that your dog ate your altimeter, so now you can no longer use it to measure the rocket's height. Luckily you happen to have a PhD in physics and you can just calculate how high the rocket will go. Not only do you have a PhD, but you also have a speedometer, so you can see the speed of the rocket when it takes off(Initial velocity). The equation $$$V_f^2 = V_i^2 + 2ad$$$ to represent the height of the rocket.
$$$V_i$$$ = initial velocity
$$$V_f$$$ = speed of the rocket at its highest point (Hint: Its not moving)
a = acceleration due to gravity (-9.8 $$$m/s^2$$$)
d = height of the rocket
A double representing the initial velocity of the rocket
The predicted height of the rocket
7.78
3.0881836734693877
While you were at science olympiad, you missed your favorite basketball team's biggest game of the year. You don't know the score, but you know the number of baskets, three-pointers, and free throws made by each team. Your task is to figure out which team won the game based on the given information. Recall that a three-pointer is worth 3 points, a regular basket is worth 2 points, and a free throw is worth one point. The number of baskets made includes three-pointers and two-pointers, but not free throws.
The first line of input contains two space-separated strings: the names of the two teams that played in the basketball game. The second line of input contain two space-separated integers representing the number of baskets made by each team, respectively. The third line of input contain two space-separated integers representing the number of three-pointers made by each team, respectively. The fourth line of input contain two space-separated integers representing the number of free throws made by each team, respectively.
Output a single string: the team that won the game. It is guaranteed that there is a winner, i.e. the score at the end of the game is not a tie.
Syracuse Duke 35 31 11 9 14 20
Syracuse
In the example, Syracuse scored 95 points, and Duke scored 91 points. This game occurred on January 14, 2019.
You are the "do-er" for the Science Olympiad event "Write it, Do it", which means that you have to interpret your event partner's written description of an object and replicate the object based on the description. Unfortunately, your partner is bad at spelling and misspelled a critical word in the description. Your task is to figure out which word your partner most likely meant to write.
The first line of input contains a string s: the word misspelled by your partner. Assume that your partner did not add or remove any letters; they only replaced letters with incorrect ones. The next line contains a single positive integer n indicating the number of possible valid words that your partner could have meant to write. Each of the next n lines contains each of these words. There is guaranteed to be at least one word of the same length as the misspelled word.
Output a single word w: the word in the dictionary of possible words closest to the misspelled word. "Closeness" is defined as the minimum number of different characters. If there is a tie, choose the word that comes first in the given dictionary of words.
deat 6 fate feet beat meat deer dean
beat
Making the rules for a competition is an important part of an online competition. For this problem, you will read the rules in the input, and print them out to the screen.
To take in input, you can use the input() command. To print out exactly what is inputted, you would do print(input()).
For this problem, you'll need to print "Competition Rules:", AND the input, on two separate lines. You should use two separate print statements.
The input consists of a single line: the rules for the competition
Output two lines. The first line should contain the string "Competition Rules:" (no quotes) The second line should re-print the rules from the input.
This is a competition rule
Competition Rules: This is a competition rule
You have made $$$n$$$ payments in the past year, and you would like to figure out how much money you have spent in total, in cents.
The first line of input contains a positive integer $$$n$$$, indicating the number of payments that you have made. The next $$$n$$$ lines each contain a positive integer $$$m$$$, indicating the amount that you paid in cents.
Output a single positive integer $$$s$$$: the amount of money that you have spent in total, in cents.
5 7 11 18 27 20
83
You consider a number to be funny if it is divisible by both 5 and 7. Given a number, figure out whether or not it is a funny number.
The only line of input contains a single positive integer n: the number
Output "YES" if the number is funny, otherwise "NO". (no quotes)
21
NO
35
YES
Your favorite soccer announcer will always say "gooooal" for a very long time after a team scores. You have a "speech to text" tool that transcribed the announcer's words. Given his written down goal reaction, figure out exactly how many "o" letters are in it.
The only line of input contains a single string $$$s$$$: the announcer's reaction to a team's goal.
Output a single integer $$$n$$$: the number of "o" letters in the given string.
goooooooooal
9
While watching the world cup, you wonder how many points your team has in the group stage. Recall that during the group stage teams are awarded three points for a win, one point for a tie, and zero points for a loss. For this problem, figure out how many group stage points your team has based on their record (wins, losses, and ties).
The only line of input contains three integers separated by hyphens (-). Each of these values represents how many wins, losses, and ties your team has had so far during the group stage, respectively.
Output a single integer p: the number of group stage points that your team currently has.
5-3-2
17
While listening to an orchestra fail to play the music from 2001: A Space Odyssey, you wonder what the lowest positive number (other than one) that divides 2001 is. It turns out to be 3 (2001 = 3 * 667). Write a program to find this value for any composite number $$$n$$$.
The only line of input contains a single positive composite (not prime) integer $$$n$$$, greater than one: the number used in your calculations.
Output a single positive integer k: the smallest positive number (other than one) that divides $$$n$$$.
2001
3
Unfortunately, you have been sent to prison because you solved too many problems at CodeQuest 2021. Now, you're trying to break out. Your cell has a combination lock with $$$n$$$ dials. You're planning to try all of the possible combinations of the lock, and you want to know how many possible combinations the lock has.
The first line of input contains a positive integer $$$n$$$: the number of dials on the lock. The next $$$n$$$ lines each contain two space-separated integers: the lower and upper limits of each lock dial. For example, if the lower and upper limits were $$$3$$$ and $$$7$$$, respectively, then the lock dial could turn to 3, 4, 5, 6, or 7.
Output a single integer $$$c$$$: the total number of possible lock combinations.
4 2 10 3 9 11 16 5 8
1512
3 1 2 1 3 11 12
12
While watching a basketball game, you wonder what your team's total free throw percentage is. You are given how many free throws each player on your team has made and attempted. Given these values, calculate your team's free throw percentage.
The first line of input consists of a positive integer $$$n$$$: the number of players on your team. The next $$$n$$$ lines consist of two space-separated integers: how many free throws each player has made and attempted, respectively.
Output a single decimal number, representing your team's free throw percentage during the game. Round your answer to two decimal places.
4 1 5 3 4 7 7 6 8
70.83
You have a broken ladder. Your ladder would normally have $$$n$$$ rungs numbered from 1 to $$$n$$$, but unfortunately some of the rungs have broken off. You can only climb up the ladder if the minimum gap between rungs is less than or equal to some value $$$k$$$. For example, if $$$k$$$ = 1, if the ladder was broken at all, you would not be able to climb the ladder.
The first line of input contains two space-separated positive integers n and k: the number of rungs remaining on the ladder, and the largest gap in rungs that you can climb over, respectively. The second line of input contains a sorted list of $$$n$$$ integers greater than or equal to 1: the positions of the rungs of the ladder. You can assume that the first and last rungs of the ladder are not broken.
Output "YES" if you can still climb the broken ladder, otherwise "NO". (no quotes)
6 2 1 2 3 5 6 8
YES
5 3 1 3 8 12 13
NO
You have a list of numbers. You want to figure out how many distinct (different) numbers are in the list. For example, the list [1, 2, 3, 4, 4, 5, 5] has 5 distinct numbers.
The first line of input contains a single positive integer $$$n$$$: the number of items in the list. The next line contains $$$n$$$ space-separated integers: the list.
Output a single positive integer $$$d$$$: the number of distinct numbers in the list.
5 2 2 3 5 6
4
4 1 2 3 4
4
You are going on a long road trip, and want to know what the maximum speed limit is in each state that you are traveling through.
The first line of input contains a positive integer S, indicating the number of states that are in the database. The next S lines each contain a string representing the name of the state, a space, and an integer representing the maximum speed limit in that state. Names of states will not contain spaces. The next line of input contains a positive integer T indicating the number of test cases that follow. Each test case will consist of a state name.
For each of the T test cases, output a single integer: the maximum speed limit in the given state, from the database.
6 NewYork 65 Texas 85 Pennsylvania 70 Massachussets 65 Washington 75 Hawaii 60 5 NewYork Pennsylvania NewYork Texas Hawaii
65 70 65 85 60
You've just bought a set of practice katanas, which have an item number of 1101-1816. While staring at this item number, you wonder what the LCM (Least Common Multiple) of 1101 and 1816 is.
To calculate the LCM of two numbers, you can multiply the two numbers together, and divide this result by the GCD (Greatest Common Divisor) of the two numbers. For example, let's take the numbers 60 and 72. Their GCD is 12 (12 is the greatest number that divides both numbers), their product (60 x 72) is 4320, and their GCD is 4320 / 12 = 360. To calculate the GCD of two numbers, you can use this recursive formula:
gcd(a, b) = a, if b = 0
otherwise, gcd(a, b) = gcd(b, a mod b)
The only line of input contains two positive integers $$$a$$$ and $$$b$$$.
Output a single positive integer $$$n$$$: the LCM (Least Common Multiple) of $$$a$$$ and $$$b$$$.
2 4
4
1101 1816
1999416
You are given a shuffled deck of cards, and your task is to return them to sorted order. Sorted order involves the cards being sorted first by their numbers, and if their numbers are equal, being sorted by their suit. In the sorting, clubs comes before diamonds, which comes before hearts, which comes before spades. The deck may not be complete, i.e. some cards may be missing. Assume that aces are always the highest possible card for this problem.
The first line of input contains a single integer $$$n$$$ (1 < $$$n$$$ <= 52): the number of cards in the deck. The next line contains $$$n$$$ space-separated blocks, each representing a card. Each block will contain one character representing the value of the card, and a second character representing the suit of the card. No "10" cards will be given in the input.
Output $$$n$$$ space-separated blocks: the deck, after sorting is complete.
10 8C 7D QH QD QC KD 2H AD 3D 7H
2H 3D 7D 7H 8C QC QD QH KD AD
You are using a code where letters in words map to digits in the following way:
0 = o
1 = i
3 = e
4 = a
5 = s
7 = t
(the other digits will not be used in this problem)
You've found a sequence of numbers, and you want to find which words the numbers correspond to using the code described above. For this problem, assume that the only letters in each word are the ones that map to numbers.
The first line of input contains a positive integer T indicating the number of test cases that follow. Each of the next T lines contains a sequence of space-separated numbers consisting of the digits 0, 1, 3, 4, 5, and 7.
Output T lines, with each line consisting of the decoded sequence of words using the code described above.
4 50 50 45 15 1 473 4 74573 17 15 70 517
so so as is i ate a taste it is to sit
Sudoku is a popular number puzzle involving placing digits (1-9) in a 9 by 9 grid. A sudoku is considered valid if all of the following are true:
-All digits are integers from 1 to 9
-No number occurs in the same row twice
-No number occurs in the same column twice
-No number occurs in the same 3 by 3 box twice.
Given a sudoku board, print whether or not it is valid.
The input consists of nine lines, each containing nine space-separated integers ranging from 1 to 9.
If the sudoku is valid, output VALID, otherwise output INVALID.
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 1 5 6 4 8 9 7 5 6 4 8 9 7 2 3 1 8 9 7 2 3 1 5 6 4 3 1 2 6 4 5 9 7 8 6 4 5 9 7 8 3 1 2 9 7 8 3 1 2 6 4 5
VALID
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9
INVALID
While watching the world cup, you wonder how many points each team has in the group stage. Recall that during the group stage teams are awarded three points for a win, one point for a tie, and zero points for a loss. For this problem, you're given a history of the games between all of the teams, and you must figure out how many group stage points each team has.
The first line of input contains a single integer $$$n$$$: the number of games played. The next $$$n$$$ lines of input consist of two space-separated integers representing the two teams that played. After the integers on each line, one character will follow (after a space) indicating the result of the game. If the character is "W", the first team beat the second team. If the character is "T", the teams tied. (the character will never be "L", i.e. the first team will never lose)
Output $$$m$$$ lines. On each line, print each team's name, and a single integer $$$p$$$: the number of group stage points that the team has. The teams should be sorted in order of their scores; if there is a tie, the tied teams should be sorted alphabetically.
6 Germany Portugal W UnitedStates Ghana W Germany Ghana T UnitedStates Portugal T Germany UnitedStates W Portugal Ghana W
Germany 7 Portugal 4 UnitedStates 4 Ghana 1
Note: this is a harder version of a previous problem in the contest.
You are using a code where letters in words map to digits in the following way:
0 = o
1 = i
3 = e
4 = a
5 = s
7 = t
(the other digits will not be used in this problem)
You've found a sequence of numbers, and you want to find how many words the numbers correspond to using the code described above.
Additionally, for this problem, assume that any letters in the original word that did not map to a letter in the code were simply encoded as blanks. Thus, a number sequence can potentially map to multiple words. Thus, you are given a dictionary of words, and you are tasked with figuring out which words in the dictionary map to the given number sequence.
The first line of input contains a positive integer D: the number of words in the dictionary. The next D lines each contain a single word: each dictionary entry. The words will be sorted alphabetically. The next line of input contains a positive integer T indicating the number of test cases that follow. The next T lines each contain a single number sequence (not separated by spaces).
For each test case, first print a positive integer K: the number of single words in the dictionary that map to the number sequence using the code described above. Then, print K lines: each word, printing the words in alphabetical order (remember that the given dictionary already is in alphabetical order).
8 fantastic funtastuc hasty taste tasted tastes tasty untasty 3 457 7457 74573
1 hasty 3 funtastuc tasty untasty 2 taste tasted
Your team qualified for the national finals of CodeQuest 2021*, and you need to figure out which flights you need to take to get to the location of the finals. However, you have a limited budget for the whole trip. Figure out the best route for your team to go to the specified location of the competition, given the possible flights and their times. If multiple routes are possible, choose the one that has the lowest price. Assume there are no layovers in airports, i.e. all of the time spent on a journey is spent on the airplanes. Your starting location is always "Syracuse"
The first line of input contains a string $$$s$$$: the location of the CodeQuest competition. The next line contains two space-separated integers $$$n$$$ and $$$b$$$: the number of flights, and your total budget, respectively. The next $$$n$$$ lines each describe one flight. Each line contains three space-separated items: two strings, representing the start and end cities of the flight, and one integer, representing the price. There will always be at least one flight departing from "Syracuse", and at least one flight arriving in "Syracuse".
If it is impossible to go to the CodeQuest finals and back with your budget, output "IMPOSSIBLE" (without the quotes). Otherwise, output two space-separated integers $$$n$$$ and $$$t$$$: the number of flights that you need, and the total price, respectively. Then, output $$$n$$$ lines, each containing the start and end cities of each flight that you are going to take, separated by an arrow (->).
SanFrancisco 9 120 Syracuse NewYork 5 Syracuse Detroit 5 Syracuse Atlanta 20 Atlanta Dallas 50 Dallas SanFrancisco 30 Detroit Chicago 1 Chicago SanFrancisco 30 SanFrancisco NewYork 10 NewYork Syracuse 10
5 56 Syracuse -> Detroit Detroit -> Chicago Chicago -> SanFrancisco SanFrancisco -> NewYork NewYork -> Syracuse
NewYork 3 10 Syracuse Detroit 9 Detroit NewYork 1 NewYork Syracuse 2
IMPOSSIBLE
SanFrancisco 8 1000 Syracuse SanFrancisco 100 NewYork StLouis 5 StLouis Portland 5 Syracuse NewYork 5 Portland LosAngeles 5 LasVegas SanFrancisco 5 LosAngeles LasVegas 5 SanFrancisco Syracuse 1
7 31 Syracuse -> NewYork NewYork -> StLouis StLouis -> Portland Portland -> LosAngeles LosAngeles -> LasVegas LasVegas -> SanFrancisco SanFrancisco -> Syracuse
*CodeQuest does not actually have national finals
Yoda tends to confuse people with his irregular syntax. Write a program that takes in a string and switches the first half of the words with the second half.
A line will contain a string.
For the input, your program must print that string with the first and second half of the words switched.
reverse this sentence you have to
you have to reverse this sentence
Assume the input will always have an even number of words.
You are on planet Omicron Persei VIII and you find that the force due to gravity on you is Fg newtons, you also know that you have a mass of M. Using this information you want to know how long it will take for an object to fall (time T in seconds) a distance D starting from rest (Vi speed when the object is initially released). Using the following equations Fg = MG and D = ViT+½GT^2.
The first line will be the force due to gravity of you (Fg), the second line is your mass (M) and the third is the distance the object is going to fall (D).
Print the time that it will take for the object to fall d meters in the following format: "It will take the object T seconds to fall D meters". Your answer should also be rounded to the nearest tenth.
500 70 10
It will take the object 1.7 seconds to fall 10.0 meters
If you are getting confused by the Vi part here is a hint. When an object is at rest, meaning not moving, what is its speed.
Given two strings that represent binary numbers, return the sum of the 2 numbers in binary.
The first line will contain the first binary number and the second line will contain the second binary number.
Print the sum of the two numbers in binary.
101 11
1000
If you need help understanding how to read numbers in binary, you can check out the following link: https://medium.com/@LindaVivah/learn-how-to-read-binary-in-5-minutes-dac1feb991e
Two runners are racing against each other in the 400 meter dash and you want to know who will win. The current distance covered by each runner(meters) and the speed (meters per second) will be given for each runner. Return whether the first or the second runner will end up winning the race assuming they travel at the speed throughout the remainder of the race.
The first line will contain a sentence describing the first runner and the second will describe the second. The following format will be used: "runner X is traveling at Y meters per second and has already covered Z meters"
Print which runner will win the race in the following format: "Runner X wins"
runner 1 is traveling at 10.5 meters per second and has already covered 100.0 meters runner 2 is traveling at 9.3 meters per second and has already covered 300 meters
Runner 2 wins
Your 5 year old cousin needs your help with some basic math. Write a program for him to do addition and subtraction.
The one and only line that you will be given is a math equation that uses addition and subtraction.
Print the following "(original equation) = (answer)".
1 + 5 + 7 - 2 =
1 + 5 + 7 - 2 = 11
A monoalphabetic cipher is a type of encryption where each letter in the alphabet correlates to another letter in the alphabet. For this question you need to decrypt a piece of text given the key used to encrypt it and the encrypted message.
The first line will be the key needed to decrypted the text and the second line will be the encrypted message. For the key that is given, the first letter of the key correlates to A, the second letter in the the key goes to B, then C and so on.
Print the following: "Decrypted text: (Decrypted text)"
azertyuiopqsdfghjklmwxcvbn miol ligwsr zt ktarazst mtvm
Decrypted text: this should be readable text
Given two arrays of integers, check if they are equal... But, if the arrays can be made equal through the removal of duplicates or sorting, they are equal.
The first line will represent the elements, n, in the first array. Then, you will be given n integers inputted on their own lines. After that, another integer will be inputted, which represents the elements, m, in the second array. Then m integers will follow, all being inputted on separate lines.
Print "YES" (without the quotes) if you these arrays are equal (or if they are equal after removing duplicates and sorting them), or "NO" (without the quotes) if the arrays cannot be made equal.
3 1 2 3 5 1 1 2 2 3
YES
4 1 2 3 4 3 1 2 7
NO
You will be given two opposite corners of two separate rectangles and you must determine whether they intersect or not.
The first line will contain 4 integers separated by spaces, which respectively represent the x-coordinate and y-coordinate of a corner of the rectangle and the x-coordinate and y-coordinate of the opposite corner. The second line will contain another 4 integers that represent the same coordinates but for the second rectangle.
Print "YES" (without the quotes) if the rectangles intersect or "NO" (without the quotes) if the rectangles do not intersect.
-5 -5 5 5 4 4 8 8
YES
The first rectangle has one corner located at (-5,-5) and the opposite corner at (5,5). The second rectangle has one corner located at (4,4) and the opposite corner at (8,8). These rectangles intersect, thus "YES" is printed
Also, if the rectangles lie on top of one another, they are intersecting. If one is inside the other and their perimeters do not touch, then they are not intersecting.
You and your friend are passing notes in class, but to secure the safety of your notes you both decide to scramble the words. Your friend is going to pass you the first note, so that you can figure out the type of scramble that was used. Use the example test case below to figure out how the words where scrambled and write a program that will scramble words in the same way.
The only line that you will be given will the plain unscrambled note that you want to send.
Print the scrambled version of the note, so that you can send a message to your friend safely.
good luck trying to figure out how this was scrambled :)
): delbmarcs saw siht woh tuo erugif ot gniyrt kcul doog
Given a tic-tac-toe board, return if you can win the game in one move or not.
The first line will be the side that you are on, X or O. The next three lines are the are the current board.
If you can win print "Yes you can.", otherwise print "No you can't."
X XOX| XO | O X|
Yes you can.
You have a meeting on a specific date. Given the current date and the date of the meeting, return how many days there are until the meeting.
The first line will contain the first date and the second line will contain the second date. They will be given in the following format: "month day, year"
If the meeting is on that date print "It is today", if it has passed print "Sorry you are X days late", otherwise print "There are X days until your meeting".
July 5, 2019 March 10, 2020
The meeting will occur in 248 days.
You do not need to account for leap years.
A train station needs your help to maximize its efficiency. The train station can only have 100 train carts parked on a track at once, and it is imperative that the tracks are fully filled as to maximize profit. Given a list of trains and their lengths (number of train carts) print the pairs of trains that will most effectively fill the station.
You will be given 4 integers separated by spaces. Each of these integers represents the number of cars on a train.
Print the pairs of trains.
25 50 50 75
Train 1 and Train 4 Train 2 and Train 3
35 24 65 76
Train 1 and Train 3 Train 2 and Train 4
In the first case, Train 1 must be combined with Train 4, as 25 cars plus 75 cars adds up to 100 cars. Train 3 must be combined with Train 4, as 50 cars plus 50 cars equals 100 cars.
Also, assume that there is always a way to fill each track with 100 trains. Make sure the output format puts the trains in ascending order (i.e. Train 1 and Train 3, not Train 3 and Train 1).
You like to use your stopwatch all the time, but there is one major problem with it. The stopwatch only displays seconds, so when it says 472 seconds have passed you have no idea what that means. Given a time in seconds display the years, days, hours, minutes and seconds that have passed.
The first line is number of seconds that have gone by.
Print the time that has passed in the following format. "X years, X days, X hours, X minutes and X seconds". If the value for any time is 0, do not include it. Also be sure to watch out for plurals and using "and". If the time is 0, say "now" .
1
1 second
98753213
3 years, 47 days, 23 hours, 26 minutes and 53 seconds
You are currently playing minecraft with your friends when you get a brilliant idea for a prank, you want to fill his entire house with sand. Given some information that represents the dimensions of your friend's house return the number of blocks of sand needed to fill it up.
The first line will contain a number that is the height of the house. The next line will be the number of lines that will be used to display the foundation of the house. The following lines will be X's that represent the foundation of the house
Print an integer that is the number of blocks needed to fill the house.
5 7 XXXX XXXX XXXX XXX XXXX XXXX XXXX
21
The ceiling, floor, and walls are included within the dimensions of the house so be mindful of that. You can also assume the ceiling is flat.
Take a single string S as input, then make all capital characters lowercase and all lowercase characters capital.
A single string S containing the string to switch.
The string S after being switched.
HeLlO
hElLo
The string will not contain spaces or non-alphabetic characters.
Take a single String as input, and output the same string after repeating certain characters by a certain number. The character 'h' should be repeated 5 times, the character 'c' should be repeated 2 times, and the character 'z' should be repeated 12 times.
A single string S containing the string to be modified.
A single string S after being modified.
schizophrenia
scchhhhhizzzzzzzzzzzzophhhhhrenia
All test cases will be completely lowercase.
Find the largest possible number that can be stored with N bits. Assume that the number is a signed integer value. Remember that the maximum value possible with a certain number of bits can be calculated with the formula $$$2^{N-1}-1$$$. When solving this problem, keep in mind that if the input is greater than 32, your programming language may not have large enough integers, so you will need to use larger variable types or arbitrary precision arithmetic. Arbitrary-precision arithmetic comes with most programming languages, for example the BigInteger class in Java.
An Integer N ranging from 1 to 64.
An Integer representing the largest possible number within the given bit size.
32
2147483647
Be careful of floating point precision errors, and be sure that your output does not print output by a power of ten, e.g. 9.77E13.
A compass has many divisions of cardinal directions, most commonly the four cardinal directions of North, East, South, and West are used, though smaller subdivisions called half winds are available. The half winds can be seen on a 16-wind compass rose, and are north-northeast(NNE), east-northeast(ENE), east-southeast(ESE), south-southeast(SSE), south-southwest(SSW), west-southwest(WSW), west-northwest(WNW) and north-northwest(NNW). For this problem, decode the acronym into the full name of the half wind direction.
A single 3 character string containing the acronym to translate.
A single string that represents the full direction name.
ESE
east-southeast
NNE
north-northeast
All inputs will be capitalized, and all outputs should be lower case with a hyphen included.
Given a string S and a list of characters C, print string S after removing all of the characters given in list C.
The first line is the string S to be modified. The second line contains integer N, which is the number of different characters to be deleted. The following N lines contain the characters to be deleted.
A single string S after deleting all of the characters that are given to be deleted.
howdy 2 w y
hod
The event horizon of a black hole, also known as the Schwarzschild radius, is the radius from a black hole at which even light can no longer escape. The formula to calculate the Schwarzschild radius of a given mass is $$$r_s=\frac{2GM}{c^2}$$$. The value $$$G$$$ is the universal gravitational constant, which you should consider to be $$$6.67*10^{-1}$$$ for this problem. $$$G$$$ is being given such a high value under the assumption that the masses being input will be incredibly large. The value of $$$M$$$ will be provided, and the value of $$$c$$$ is the speed of light, which you should consider to be $$$3*10^{4}$$$ for this problem. The value of $$$c$$$ is being decreased due to the incredibly low values that it normally produces.
A single floating point value M that represents the mass of the object. The value of M will be between 0 and 1000000000.
A single floating point value that represents the Schwarzschild radius of the object.
1000000
0.0014822222222222222
Make sure to use the shortened values for $$$G$$$ and $$$c$$$ provided in the question, and not the more precise actual values. The reason that the values for $$$G$$$ and $$$c$$$ have been changed is that the use of their actual values causes such low floating point values that errors can occur, and handling such errors is not the goal of this problem. When actually calculating the event horizon, the real values of $$$G$$$ and $$$c$$$ should be used.
When using an automobile, one often seeks to understand what they will be expected to pay for the usage of gas resources. The cost of driving a certain distance can be calculated based on the miles per gallon(mpg) of the car, the distance traveled, and the cost per gallon currently. Taking in these three values as input, determine the total cost of the trip.
The first line contains three space-separated floating point values that represent the miles per gallon, distance, and cost per gallon respectively.
Output a single floating point value that represents the dollar cost of the designated trip.
10 100 3.5
35.0
When performing calculations on linear equations, finding the intersection point of two lines is a very common task. Write a program that takes two linear equations in the form of $$$y=mx+b$$$ and outputs the $$$x$$$ coordinate at which the two lines intersect.
The first line contains two floating point values representing the $$$m$$$ and $$$b$$$ values of the first linear equation respectively. The second line contains the two variables corresponding to the $$$m$$$ and $$$b$$$ variables of the second linear equation.
A single floating point value that represents the $$$x$$$ coordinate at which the two lines intersect.
5 3 -6 -20
-2.090909090909091
Assume that all test cases contain lines that do intersect.
As computers have become more and more powerful, the use of artificial intelligence has become ever more prominent in modern computing. As a result, a mechanism called a neural network has become a very commonly used tool for replicating the basic biological processes that result in the function of the brain. Neural Networks are composed of a series of "layers" of nodes, where each node of layer $$$i$$$ will connect with every node of layer $$$i+1$$$.
The first line contains a single integer $$$N$$$ that represents the number of layers. The next line contains $$$N$$$ space-separated integers that represent the number of nodes in each layer respectively.
A single integer that represents the total number of weights in the network.
3 5 10 5
100
When an object is rotating around a central point in circular motion, a force called centripetal force exists. Centripetal force is the force that pulls the object towards the center, preventing it from flying off in a straight line. An equation exists to relate the centripetal force $$$F_c$$$, the mass of the object $$$m$$$, the tangential velocity $$$v$$$, and the radius of the circle $$$r$$$. This equation is represented as follows: $$$F_c = \frac{mv^{2}}{r}$$$. To solve this problem, you will be given the centripetal force, the mass of the object, and the radius of the rotation. With this information, determine the tangential velocity of the moving object.
The first line contains three space-separated floating point values that represent the centripetal force, the mass of the object, and the radius of the rotation respectively.
Output a single floating point value that represents the tangential velocity of the movement.
100 10 5
7.0710678118654755
When trading securities such as stocks and crypto-currencies in the markets, many traders look at mathematical tools called indicators. There are hundreds of different indicators for all sorts of purposes, but one of the most commonly used indicators is called the relative strength index, or RSI for short. The RSI provides an estimate of how the price of a security is likely to move, with a high RSI value(above 70) suggesting the item is overpriced and will decrease in value, while a lower value(below 30) suggests the opposite. The RSI is calculated with a simple formula that is based on the past prices of a security. This formula is given as: $$$100-(100/(RS+1))$$$ where $$$RS = aveUP/aveDOWN$$$. $$$aveUP$$$ is the average value among all of the times the price of the security increased between two measurements, and $$$aveDOWN$$$ is the average value among all of the times the price of the security decreased between two measurements. For this problem, take in the past $$$N$$$ prices of an asset, then determine the value of the RSI indicator. It is important to note that aveDOWN should be composed of the absolute value of each price decrease between two measurements, and therefore should have a positive value.
The first line contains an integer $$$N$$$ representing the number of prices that will follow. The next line contains $$$N$$$ space-separated floating point values that correspond to each measurement of the price, with the first measurement being the first value provided.
A single floating point value that represents the value of the RSI indicator for the given price history.
4 6500.0 6510.0 6300.0 6200.0
6.060606060606062
Note that in real market RSI calculations, an exponential moving average(EMA) is used to process faster moving data, but you should use a simple moving average(SMA) to find the aveUP and aveDOWN values. A simple moving average is the same as finding the average value of a number set as you usually would. It is also very important to note that aveDOWN should include the absolute value of each decrease, and should therefore have a positive value. You can also assume that there will always be at least one price increase and at least one price decrease in the given data
Bob is attempting to encrypt information so that only those he trusts with the secret code can decode his secret information. Instead of using a highly secure encryption method, bob uses a method called rotation, where he shifts each letter of his phrase a certain number of characters up or down. This shift works by moving the character up and down the alphabet, so the character 'a' shifted by 5 would become 'f'. A shift also wraps around the alphabet, so if you were to shift 'a' by -5, it would become 'v'. In addition, a character can be shifted by values greater than 26, so for example 'a' shifted by 30 would become 'e', wrapping all the way back around the alphabet. To solve this problem, you will be given a single lowercase string and a series of rotations, with each rotation corresponding to the character in the string with the same index. Perform each rotation on each character and determine what the resulting string would be.
The first line contains a single lowercase string of length $$$N$$$ with no spaces that represents the text to be rotated. The next line contains $$$N$$$ space-separated integers that represent the shift performed on the corresponding character of the original string.
A single lowercase string that represents the original string after performing the shifts.
agjnp 7 -2 54 -80 25
hello
As you may know, large prime numbers are in very high demand currently, and there are many large scale searches for even larger primes. Some of the largest prime numbers discovered fit a number called a Mersenne Prime, which is essentially any prime number than can be represented by the equation $$$2^{p}-1$$$. Mersenne Primes are especially interesting as they can be tested for primality with a special test called the Lucas-Lehmer test. Although you could technically solve Mersenne Primes using typical prime-number algorithms, the Lucas-Lehmer test will almost always be faster. The pseudocode for conducting the Lucas-Lehmer test for as found on Wikipedia is as follows:
A single integer $$$p$$$ that represents the power of 2 in the equation $$$2^{p}-1$$$ to be tested.
The phrase "true" should be printed if the value calculated with $$$p$$$ is a Mersenne Prime, and the phrase "false" should be printed otherwise.
7
true
15
false
More information regarding the Lucas-Lehmer test and Mersenne Primes can be found here: https://en.wikipedia.org/wiki/Lucas-Lehmer_primality_test, https://en.wikipedia.org/wiki/Mersenne_prime.
In a previous contest, a question was asked about determining how many days apart two dates were, ignoring leap years. This question is essentially the same, except it includes leap years. In addition, this question only asks for the count of days from $$$date 1$$$ to $$$date 2$$$, and $$$date 2$$$ will always be after $$$date 1$$$. Take in two dates in the form of month-name day-number, year. Then print out the number of days from the first date to the second one, and make sure that your calculation includes the addition of days added by leap years.
The first line contains the first date in the form of month day, year. The month is provided as a capitalized name, and not a number. The second line contains the second date in the same form.
A single integer representing the number of days from the first date to the second.
June 21, 2019 June 21, 2020
366
The second date will always be after the first. Make sure to consider leap years. If you have difficulty with the input, be sure to carefully follow the formatting.
Given the three points that represent the corners of an isosceles triangle, determine the angle that the triangle is pointing. The angle can be calculated based on the vector created along the line of symmetry of the triangle that exits through the point of the triangle. The angle should be represented in degrees and should be determined relative to the vector (1,0). The following image shows a triangle with points at (-1,0), (0,1), and (-2,2), and has an angle of 135 degrees.
Each line contains two space-separated floating point values that represent the $$$x$$$ and $$$y$$$ values of each point of the triangle. They are randomly ordered.
A single floating point value that represents the degree measure of the angle created from the positive x-axis to the direction of the triangle.
-2 2 0 1 -1 0
135.0
Make sure answers are provided in degrees and fall within the range of 0 to 360.
For the first problem, we'll keep it simple to make sure you understand how this format works.
Finish the given sentence by adding the string Mario! to the end of the statement.
Return the completed sentence.
It's a me,
It's a me, Mario!
You have acquired the Infinity Gauntlet from Thanos from the Marvel Universe. For those who are unfamiliar with the Infinity Gauntlet, it contains immense power with the ability to many things, but most notably, to reduce numbers into half.
The first line will contain integer $$$n$$$ that will denote the amount of test cases that will follow, and each line after the first will contain an integer that is to be divided in half.
Output a series of line-separated floating-point values which divides the inputs in half.
5 10 32 12 35 52
5.0 16.0 6.0 17.5 26.0
You've been selected to be the recipient of Wegman's shopping spree program! The only caveat is that you have to be continuously moving through the building at all times, through the different sections in a circular pattern, so you will only have time to grab one item from each section. It will also take some time for you to move to the different locations of the store, and luckily, this Wegmans only has 3 sections, as the architect designing this location was lazy with his design.
You want to know how many loops it will take you to get a certain amount of different types of items.
The first line will contain an integer $$$n$$$, which denotes the amount of test cases that will follow. These test cases will each contain 3 different, space-separated integers denoting the amount of different items you will need to complete the shopping list.
The first line will always be Produce $$$p$$$, the second will be Meat $$$m$$$, and the third will be dry goods $$$d$$$.
Return the amount of loops it will take for you to complete your shopping list.
3 2 6 1 3 2 1 1 5 7
6 3 7
Getting back from the grocery store, you bought a whole bag of candies just for you to eat. You put the candy in a jar, and hide it in your room. Unfortunately, you notice that the number of candies in the jar are going down each day, but you do not know by how much.
You want to know how much the thief has stolen every day.
The first line $$$n$$$ will denote how much candy you had initially, and the second line will always contain a series of descending space-separated integers which indicate the amount of candy remaining each day, starting from the day the first candies were stolen.
Output a set of line-separated integers which answers the amount of candy stolen from the candy jar each day.
100 97 92 85 80 72 65
3 5 7 5 8 7
(It turns out that you caught your siblings stealing from your jar while you were absent from your room. Those rascals!)
You are an event organizer, tasked with planning an event in a very large, outdoors area. However, you only have two very powerful speakers, which are placed on both ends of the stage.
You assume that there will be crowds spanning large lengths at this meeting, and need to figure out how long it takes for the sound from the stage to reach the furthest attendees of the event.
However, an engineer helping to organize the event reminds you that the speed of sound is varied, depending on the temperature. As you are planning the event in Syracuse, this is a serious problem, as the temperatures are very unpredictable.
The approximate formula for the speed of sound (assuming there is no humidity in the air, is):
$$$V = (331.3 + .606∙\vartheta)$$$
Where $$$V$$$ is the speed of sound in meters per second, and $$$\vartheta$$$ is the temperature of the air, in degrees Celsius.
The first line of the input will denote integer $$$n$$$, the number of test cases following the line. The lines following will contain two values each, the first being the integer temperature $$$\vartheta$$$, and second being the distance between the stage and the furthest edges of the crowd, measured in km.
Output the time it takes for the sound from the stage to reach the furthest edges of the crowd in seconds, rounded to the nearest hundred.
5 7 3.6 24 1.1 17 4.4 -1 1.2 8 5.9
10.73 3.18 12.88 3.63 17.55
Throughout this global pandemic, many health experts and doctors are steadfast on the effort to "flatten the curve", or to decrease the maximum amount of people who are getting infected by the virus, using the method of social distancing, one of the reasons why we are in quarantine at this very moment.
The daily rate of infection, if left unchecked, can look a lot like this logistic function, where $$$\Delta N$$$ is the total number of cases, $$$\Delta t$$$ is the time period for new infections, (which, in this case, would be one day.)
$$$\frac{\Delta N}{\Delta t} = a(1-\frac{N}{N_{max}})N$$$
$$$a$$$ is the infection rate, which, for COVID-19, would be .394 (with social distancing, the number is able to go down). Finally, $$$N_{max}$$$ is the total amount of infections we can expect for the curve to flatten. In this simulation, we will calculate the total number of days $$$t$$$ the virus will take in order for it to infect the entire population of America dependant on its infection rate, which will be about 320 million people.
The first line will contain the integer $$$n$$$, which denotes the amount of test cases that will follow. Each line below the first line will contain a floating point value $$$a$$$, which is the infection rate for that test case.
Let $$${N_{max}}$$$ be equal to around 328.2 million people, which is the entire population of the US, however, you should output the number of days it takes for the virus to infect 320 million people, which is a vast majority.
4 .394 .212 .107 .059
67 118 226 403
($$$N$$$ will also have an initial value of 1)
A color wheel is a tool used to determine the relationships of different colors, often by the distance between two colors on the wheel.
Using the given simple color wheel above, your task is to determine the shortest numerical distance between two colors.
The first line will contain an integer $$$n$$$, the number of test cases that will follow. The next lines will contain two strings in each individual line, which will be the two colors that will taken under measurement. (All colors will have the same name as the colors of the image above)
Return the int value of the distance between the two colors, including the last color, but excluding the first.
3 green red purple orange blue blue-green
3 2 1
(All inputs will be in lowercase)
Leet, (also known as 1337 sp34k or Elite Speak), was a prominent use of letter swapping during early internet culture.
Set types of letters would be able to be substituted for different numbers which would have similarities to the letters they were replacing. For this basic translator, only these conversions are needed:
a = 4 b = 8 e = 3 i = 1 l = 1 o = 0 s = 5 t = 7 z = 2
Will contain a single string to be translated
Return a leet translated piece of string
this is a test input
7h15 15 4 7357 1npu7
You have an in-home library, but its organization is a mess! Fantasy books next to non-fiction biographies, detective novels next to ancient classics, and worst of all, the author's names aren't in alphabetical order!
To fix this problem, you decide to create a program that is able to divide the books into different genre groups, with the authors of the genres listed in alphabetical order.
The first line will contain the number of books that are in the library, and the following lines will contain books in this format, with the author's last name as the first word, and the genre as the second word, with both being separated by a space.
Output a line of string that will contain a single Genre, and the list of authors writing in that genre in alphabetical order, in this format: <genre>: <aauthor1>, <bauthor>, <cauthor>
7 Bradbruy scifi Asimov scifi Kafka dystopian Huxley dystopian Tolkien fantasy Collins dystopian Herbert scifi
dystopian: Collins, Huxley, Kafka fantasy: Tolkien scifi: Asimov, Bradbruy, Herbert
(For the order of the genres, please make sure that they are also in alphabetical order.)
(It can also be assumed that all genres and authors will contain one word, but last names will have proper capitalization conventions.)
The FBI has been working hard to find the location of a criminal organization by analyzing their use of repeating patterns in sections of their internal communications. So far, this process has been entirely manual and is therefore slow, so you are tasked with creating a program to automate this pattern finding. Determine whether or not a section of text repeats a single string multiple times. The problem is that you don't know what string it is that is being repeated, though you do know that the pattern will always begin immediately. A pattern will always appear as the same string being repeated at least twice. It is also important to note that there can be unimportant text that follows the repetition that is not a part of the pattern. All of this following text should be ignored. It is also important to note that the repeated string must be at least two characters.
A single string that represents the string to analyze.
A single statement of "True" or "False" that states whether or not there is a pattern.
hellohelloasd
True
The Octal Numeral system is a Base-8 number system, with the same concept and algorithm as other number systems, such as binary and hexadecimal. The advantages of using the base 8 system, is that all of its components are made of numbers, unlike the hexadecimal system, and is shorter than the binary system.
The input will be composed of different integer values depicting octal values, separated by spaces, which represent a certain Unicode value once converted into a decimal.
Output the translated string.
164 150 151 163 40 151 163 40 141 40 160 162 157 160 145 162 40 157 165 164 160 165 164
this is a proper output
On a regular acoustic guitar, the open (regular) strings are tuned with these notes, starting from lowest to highest:
You can change these values into different notes using the tuning pegs on the top of the guitar, twisting it forwards or backwards to change the pitch of the strings. One full rotation of the peg would be equivalent changing the pitch by one semitone, or a half step in pitch. For instance, using the piano keys up above, F would move up to F#, or if moved down a semitone, would be moved down to an E.
When given certain note values, your job is to tune the song based on how many semitones you are given. This is known as transposing.
The first line will contain an integer n which will denote the semitone value you are to transpose the piece to. The second line will contain a space-separated line of strings ranging from the notes A-G#.
Output a new line of the transposed piece, with each note being space-separated.
-3 E A D G B E
C# F# B E G# C#
3 E A D G B E
G C F A# D G
Though you may have completed the previous task to analyze and find patterns in sections of text, the FBI has realized that it needs a more powerful program that is able to find more complex patterns and with more constraints. Your new program should be able to identify if a repetition pattern exists within a string regardless of where it starts. You will also be supplied with a number that represents how many repeats there should be. Your program should only output "True" if the number of repetitions precisely matches the number provided.
The first line contains the string to be analyzed. The second line contains a single integer that represents the number of repetitions to look for.
A single statement of "True" or "False" that indicates whether or not a repetition pattern exists with the repeat number provided.
uyboubawlefjbasdHELLOHELLOHELLOHELLOsygvfubklkj 4
True
There can be unneeded text before and after the repetition, and this should be ignored.
Bob has an array of integers, and Bob is curious whether or not his array is symmetrical on two axis of symmetry. Write a program that takes in an array of integers and outputs whether or not the array is symmetrical. The two axis of symmetry are the horizontal and the vertical. It is important to note that if an odd number of columns or rows is present, the middle row and/or column(s) should be considered the axis and should be completely ignored in the symmetry analysis. Integers are considered symmetrical if they are the same value across an axis of symmetry. Your program should only output "True" if the array is symmetrical on both the horizontal and vertical axis of symmetry.
The first line contains two space separated integers, $$$R$$$ and $$$C$$$, respectively. These represent the number of rows and columns that are in the array. The next $$$R$$$ lines will each contain $$$C$$$ space-separated integers that represent the individual elements of the array.
A single statement of "True" or "False" that indicated whether or not the array is symmetrical.
5 5 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 0 1
True
3 3 1 1 1 0 1 0 1 0 1
True
Welcome to the CodeRams Contest #8, and thanks for participating!
We like to make contests with themes that tie together all of the problems. For this contest, the problems are all based on songs by the German band Kraftwerk. We'll provide links to each of the songs in each corresponding problem. We recommend that you listen to each song while you are solving each problem. (You're allowed to view the provided links, despite them requiring use of the internet.)
The Robots (the song corresponding to this problem)
For this first problem, you want to train your robot army to print out a given string of text three times.
The only line contains a single line of input, consisting of any ascii characters.
Print the line of text given in the input three times, with each one separated by a new line.
We Are The Robots
We Are The Robots We Are The Robots We Are The Robots
You're trying to determine how many neutrons are in a certain radioactive isotope. You know how many protons are in the isotope, and you know the isotope's mass number. The mass number of an isotope is defined as the number of protons plus the number of neutrons. Given the number of protons and the mass number, figure out how many neutrons are in the radioactive isotope.
The only line of input contains two space-separated integers $$$p$$$ and $$$m$$$ ($$$p$$$ <= $$$m$$$), representing the number of protons in the isotope, and the mass number of the isotope, respectively.
Output a single positive integer $$$n$$$: the number of neutrons in the radioactive isotope.
92 238
146
36 85
49
You are making a model airplane, which will be powered by rubber bands. Luckily, to speed up the process of winding the rubber bands, you have a crank winder, which has a certain ratio (e.g. 15:1), representing how many winds of the rubber band one turn of the winder will result in. Given this value, and how many winds you ultimately want the airplane's rubber band to have, figure out how many times you need to turn the winder.
The first line of input contains a single positive integer $$$n$$$, representing the number of winds you want the plane to have. The second line of input contains a single positive integer $$$m$$$, representing how many winds of the rubber band one turn of the winder corresponds to.
Output a single positive integer $$$w$$$: how many times you need to spin the winder. This value is guaranteed to be an integer.
2250 15
150
64 4
16
For the first example, $$$150.0$$$ would also be judged as a correct answer.
You just bought a new computer, and you wonder if it has a large, medium, or small amount of storage on its hard drive. The storage of your computer's hard drive will be given in gigabytes (GB).
If your computer's storage space is less than or equal to 200 GB, you consider it SMALL.
Otherwise, if your computer's storage space is less than or equal to 500 GB, you consider it MEDIUM.
Otherwise, you consider it LARGE.
Given these storage space bounds, figure out whether or not your computer's storage is SMALL, MEDIUM, or LARGE, and print the answer accordingly.
The only line of input contains a string indicating how much storage space your computer has, with a "GB" on the end. For example, if your computer had 300 gigabytes of storage, this would be read as "300GB" (no quotes) in the input.
Output a single string: SMALL, MEDIUM, or LARGE (all caps), classifying your computer's storage space as described above.
800GB
LARGE
200GB
SMALL
450GB
MEDIUM
With the CodeRams club, you've created a lab in space to study solar power. You created your lab on a planet in our solar system. Unfortunately, a rival CodeQuest team also created a spacelab on a different planet. You need to figure out which spacelab is closer to the sun.
For reference, the order of the planets in our solar system from closest to farthest away from the sun is "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" (you can copy this into a list/array if you want).
The first line of input contains a single string, representing the planet that your spacelab is located on. The second line of input contains a single string, representing the planet that the rival team's spacelab is located on. The planets given are guaranteed to be in our solar system, and no TNOs, dwarf planets, or asteroids will be given in the input.
If your spacelab is closer to the sun than your rival's, output "CLOSER" (no quotes)
If your spacelab is farther away from the sun than your rival's, output "FARTHER AWAY" (no quotes)
If your spacelab is on the same planet as your rival's, output "THE SAME" (no quotes)
Mars Jupiter
CLOSER
Uranus Mercury
FARTHER AWAY
Neptune Neptune
THE SAME
You want to call Lockheed Martin to register your team for CodeQuest 2021, but you don't know their phone number. However, you know some of the digits of the phone number. You're going to try to call all possible phone numbers, given the digits that you know, and you want to know how many numbers you're going to have to call. For this problem, assume that all area codes are valid.
The only line of input contains a string of length 10, with each position in the string containing a digit from 0-9, if you know the digit at that position in the phone number, and an "x" if you don't know the digit.
Output a single positive integer $$$n$$$: how many possible phone numbers there are, given that you already know the digits listed in the input.
315xxxx8x9
100000
1234567890
1
xxxxxxxxxx
10000000000
Note that the answer does not necessarily fit inside of a 32-bit integer type, in tests like the third example. The answer will fit inside of a "long" in Java. (You don't need to worry about this in Python)
You're trying to find the longest possible piece of music, so that you can play music non-stop. Given a list of songs and their durations (in MM:SS, with leading zeros), figure out which song is the longest.
The first line of input contains a positive integer $$$n$$$: the number of songs. The next $$$n$$$ lines contain a string, representing the song title, a space, and the song's duration, in MM:SS format with leading zeroes. (For example, a song that was 7 minutes and 9 seconds long would be written as 07:09).
Output a single string: the name of the longest song given in the input. If two songs have the same length, output the one that comes first in the input.
6 TheRobots 06:13 Spacelab 05:57 Metropolis 06:01 TheModel 03:41 NeonLights 08:53 TheManMachine 05:32
NeonLights
4 ReallyShortSong 01:30 ReallyLongSong 18:16 AnotherReallyLongSong 18:16 NotAsLongSong 11:01
ReallyLongSong
You love your computer, and you want to give it a present: a large integer. However, your computer especially loves powers of two. Given two numbers $$$x$$$ and $$$y$$$, find the largest power of two between $$$x$$$ and $$$y$$$, i.e. find the largest number $$$n$$$ such that $$$x$$$ <= $$$n$$$ <= $$$y$$$, and $$$n$$$ is a power of two.
The only line of input contains two space-separated integers $$$x$$$ and $$$y$$$: the lower and upper bounds of the range described in the problems statement. The values are inclusive, i.e. $$$x$$$ and $$$y$$$ could potentially be valid answers if they were powers of two.
Output a single integer $$$n$$$: the largest power of two such that $$$x$$$ <= $$$n$$$ <= $$$y$$$. If there aren't any powers of two between $$$x$$$ and $$$y$$$, output $$$-1$$$. The answer is guaranteed to be within the bounds of 32-bit signed integers.
6 18
16
35 55
-1
86 375
256
After listening to the Kraftwerk song Techno Pop, you decide that you want to pop a balloon. You have a spherical balloon that will pop when it reaches a volume of $$$v1$$$ in^3, and you blow up the balloon inside of a cube-shaped box with a volume of $$$v2$$$ in^3.
Given these values, figure out whether or not it is possible to pop the balloon in the cube-shaped box that you have.
Recall that the formula for the volume of a sphere is $$$\frac{4}{3}\pi{}r^3$$$, where $$$r$$$ represents the radius of the sphere, and the formula for the volume of a cube (or a cube-shaped box) is $$$s^3$$$, where $$$s$$$ represents the side length of the cube.
The only line of input contains two space-separated integers: $$$v1$$$ and $$$v2$$$, representing the volume that the spherical balloon needs to be greater than or equal to in order to pop, and the volume of the cube-shaped box, respectively. Both values are given in $$$in^3$$$.
Output "YES" (no quotes) if the balloon can pop inside of the box, and "NO" (no quotes) otherwise.
10 27
YES
10 8
NO
In the first example case, the balloon has room to inflate to at most 14.1 $$$in^3$$$, so the balloon can inflate to 10 $$$in^3$$$ and pop.
In the second example case, the balloon only has room to inflate to 4.2 $$$in^3$$$, so the balloon cannot pop inside of the cube-shaped box.
You're working with large numbers, and you want to calculate the totient function of a certain one. The totient function of a number $$$n$$$ is defined as the number of positive integers less than or equal $$$n$$$ that are relatively prime with $$$n$$$, i.e. the number of integers $$$k$$$ such that $$$k$$$ <= $$$n$$$ and $$$gcd(k, n) = 1$$$.
For example, the totient of $$$15$$$ is $$$8$$$, because 1, 2, 4, 7, 8, 11, 13, and 14 are relatively prime with $$$15$$$, while 3, 5, 6, 9, 10, 12, and 15 are not. 4 is relatively prime with 15, because there aren't any common factors of 4 and 15. 4 has factors {2}, and 15 has factors {3, 5}. On the other hand, 10 is not relatively prime with 15, because 10 and 15 both have a common factor of 5.
Given an integer $$$n$$$, figure out the value of $$$φ(n)$$$, where $$$φ$$$ represents the totient function as described above.
The only line of input contains a single positive integer $$$n$$$ less than 1000.
Output a single positive integer $$$p$$$: the value of $$$φ(n)$$$ as described above.
15
8
60
16
7
6
You are trying to find strings of text to put on neon lights. You want to fully test the extent of the neon lights' writing style for letters, so you want to pick the string of text that has the highest number of distinct (different) letters from a selection of possible strings of text.
The first line of input contains a positive integer $$$n$$$ indicating the number of strings of text that you are considering putting on neon lights. The next $$$n$$$ lines each contain each string of text, consisting of only lowercase letters and spaces.
Output the string of text from the possibilities which has the highest number of distinct letters. If two strings of text contain the same number of distinct letters, choose the one that comes first in the input file.
6 coderams club neon lights kraftwerk this is a long string of text abababababababababcabababab short
this is a long string of text
3 the quick brown fox jumps over the lazy dog abcdefghijklmnopqrstuvwxy hello world
the quick brown fox jumps over the lazy dog
3 abcde abc edcba
abcde
You are trying to discover that it's more fun to compute, and you're doing so by evaluating long strings of text. You define the fun-ness of a string to be the amount of characters in the string that are equal to "f", "u", and "n". You can perform cyclic shifts on the string an infinite number of times. When you cyclically shift the string, each character changes into the one after it, so any "a" characters become "b", "b" becomes "c", etc. "z" characters turn into "a" in a cyclic shift.
Given that you can perform an infinite number of cyclic shifts on the input string, find the maximum fun-ness of the string.
The only line of input contains a single string $$$s$$$, consisting of only lowercase a-z characters and spaces. (When you perform a cyclic shift on the string, nothing happens to the spaces).
Output a single positive integer $$$n$$$: the maximum possible fun-ness of the string, as described above.
hello world
5
coderams contest number eight
9
You are about to drive on the Autobahn. You have several different cars, and you're trying to decide which one to take on the Autobahn. The different cars have differing fuel efficiencies, measured in miles per gallon (MPG), and the cars have different top speeds. You calculate a car's score as its fuel efficiency (MPG) multiplied by its top speed.
Given the list of possible cars, your task is to sort them by their score.
The first line of input contains a single positive integer $$$n$$$: the number of cars. The next $$$n$$$ lines each contain the data for a car: the name of the car, its fuel efficiency in MPG, and its top speed.
Output $$$n$$$ lines, each consisting of a car, sorted by their score as described above. Each line should be in the same format as its corresponding line in the input file. The car with the lowest score should appear first, and the car with the highest score should appear last. If two or more cars have equal scores, sort them alphabetically by the names of each car.
5 Porsche 8 200 Ferrari 7 250 Lamborghini 6 220 BMW 5 230 MercedesBenz 10 160
BMW 5 230 Lamborghini 6 220 MercedesBenz 10 160 Porsche 8 200 Ferrari 7 250
You have a circuit consisting of many resistors in parallel, and you want to calculate their equivalent resistance, in ohms.
If you competed in our Contest #2 back in January, you might remember that the formula for calculating the equivalent resistance of two resistors in parallel with resistances $$$a$$$ and $$$b$$$ is $$$(a * b) / (a + b)$$$.
To calculate the equivalent resistance of three parallel resistors, first calculate the equivalent resistance of the first two using the formula described above. Then, use the formula again to calculate the equivalent resistance of the third resistor and the value you just calculated, the equivalent resistance of the first two resistors. Calculating the equivalent resistance of more than three resistors works in a similar way.
Formally, the equivalent resistance of $$$n$$$ resistors can be calculated by plugging in the equivalent resistance of the first $$$n - 1$$$ resistors, and the resistance of the $$$n$$$th resistor, into the above formula.
The first line of input contains a positive integer $$$n$$$ greater than one, indicating the number of resistors in the circuit. Assume that all of the resistors are in parallel with each other. The next line contains $$$n$$$ space-separated positive integers, each representing the resistance of a resistor in the circuit.
Output a single positive decimal number: the equivalent resistance of the circuit. You don't need to (and you shouldn't) round your answer.
9 37 23 56 85 41 99 33 22 11
3.319115819885067
2 11 19
6.966666666666667
You're driving through a metropolis. The metropolis can be represented as a 2D grid of buildings, each with a height value between $$$0$$$ and $$$9$$$. You consider a building to be a skyscraper if it has a greater height than all of the buildings directly adjacent to it (including diagonally). Given this 2D grid of building heights, figure out which buildings are skyscrapers, and which ones aren't.
The first line of input contains a positive integer $$$n$$$: the height and width of the metropolis. The height and width are always equal, so the metropolis is always a square. The next $$$n$$$ lines each contain strings of $$$n$$$ characters, each character being a digit from $$$0$$$ to $$$9$$$ representing the height of each building.
Output $$$n$$$ lines. Each line should consist of a string of $$$n$$$ characters, with each character being $$$Y$$$, if the building at that position is a skyscraper, and $$$N$$$ if it is not.
5 35689 85723 39109 00004 39580
NNNNY NNNNN NYNNY NNNNN NYNYN
3 999 999 999
NNN NNN NNN
You have a pocket calculator. Unfortunately, it is broken, so you need to calculate large math operations yourself. For this problem, you need to write a computer program to calculate the answer to a long math operation, with multiplication (denoted by an asterisk *), division (denoted by a slash / ), addition, and subtraction. There will not be parentheses or exponents. Recall order of operations: multiplication and division (with equal weight) from left to right first, followed by addition and subtraction (with equal weight) from left to right. Using eval() or similar commands for this problem is not allowed.
The only line of input contains a line of text representing a math operation to calculate. The math operation will consist of one-digit numbers and the four operations described above, with exactly one space between each one. The input line will start and end with a number, and there will not be an equals sign at the end of the operation.
Output a single integer: the answer to the math operation. The answer is guaranteed to fit inside of a 32-bit signed integer type. The answer is also guaranteed to be an integer.
7 + 5
12
3 - 6 * 3
-15
3 + 4 * 3 - 6 / 3 * 3
9
In the third sample, $$$9.0$$$ would also be judged as correct.
You are programming your home computer. You want your computer to learn Calculus, so today you decide to write a computer program to calculate the derivative of a polynomial function.
The derivative of a "power function" $$$x^n$$$ is defined as $$$nx^{n-1}$$$. For example, the derivative of $$$x^5$$$ would be $$$5x^4$$$.
The derivative of a constant multiple of a power function $$$kx^n$$$ is defined as $$$knx^{n-1}$$$. For example, the derivative of $$$3x^4$$$ would be $$$12x^3$$$.
When taking the derivative of several terms added or subtracted to each other, you take the derivative of each term individually. For example, the derivative of $$$3x^5 - 5x^4$$$ would be $$$15x^4 - 20x^3$$$.
The "power rule" described above works intuitively if all terms have at least a degree of two (the number that $$$x$$$ is taken to the power of). For terms with a degree of one, such as $$$7x$$$, the derivative is just the constant multiple in front of $$$x$$$, which is $$$7$$$ for this example. For constant terms (with a degree of zero), the derivative is zero, and can be cancelled out.
Using this knowledge, your task is to write a program to determine the derivative of a given polynomial function.
The only line of input contains a polynomial function. Each term in the polynomial function will be separated either by " + " or " - " (with a space on either side). See the example inputs to further understand the formatting. Additionally, you are guaranteed that the first term in the polynomial is not a constant.
Output a single line, consisting of a polynomial, in the format described above: the derivative of the given polynomial function.
5x^5 + 3x^4 + 2x^3 + 8x^2 + 9x + 10
25x^4 + 12x^3 + 6x^2 + 16x + 9
x + 10 + 3x + 5 + 8x + 16x^7 + 8x^30 + 300x^200
1 + 3 + 8 + 112x^6 + 240x^29 + 60000x^199
If you're using Java, take in the line of input, and use the .split(" ") command to separate it by spaces, rather than using scn.nextInt() or something similar.
You're traveling on the Trans Europe Express, which consists of many train lines between cities. You want to know how many cities you can reach from a given start city, traveling only on the Trans Europe Express.
For example, if you started in City A, and the Trans Europe Express had train lines between City A and City B, City B and City C, and City D and City E, you could travel to City B or City C, but not to City D or City E.
For problems like these, you can use the graph theory algorithm Breath-First Search (BFS). The algorithm is described below in pseudocode:
1. Define an empty list of cities. Add the start city to the list.
2. Select the first city in the list of cities, and remove it from the list.
3. Mark the selected city as visited
4. For any edges that connect the selected city to another city, add the other city to the list of cities, if the city has not been visited yet
5. If the list of cities is not empty, repeat steps 2-4.
Then, the answer would be the number of cities that have been visited.
The first line of input contains two space-separated positive integers $$$n$$$ and $$$m$$$: the number of cities, and the number of train lines on the Trans Europe Express. The next line of input contains a single string $$$s$$$, representing the start city. The next $$$m$$$ lines contain one of the train lines of the Trans-Europe Express: two space-separated strings: the cities that the train lines connect. The train lines can be traveled in both directions.
Output a single integer $$$c$$$: the number of cities that you can visit by traveling only on the Trans Europe Express train lines.
8 7 Dusseldorf Dusseldorf Frankfurt Frankfurt Berlin Berlin Hamburg Berlin Prague Vienna Salzburg Salzburg Zurich Zurich Vienna
5
3 2 Syracuse Syracuse Utica Syracuse Rochester
3
Given that the pseudocode of the algorithm treats the cities as numbers rather than names, you should first map each city name to a number, before running the BFS algorithm.
You are trying to test your vision using an eye test chart, and you want to see if you have 20/20 vision or not. You attempt read the text on the chart, and you unfortunately get some of them wrong. Now, you're curious how close you were to correctly reading the text.
You consider some pairs of letters similar. For example, "D" and "P" look relatively similar from far away. Given the letter pairs that you consider to be similar to each other, your task is to figure out how many of the letters you got right, how many you were close on (the letters were similar), and how many you got completely wrong (the letters were not similar). Note that letters are also similar to letters that its similar letters are similar to. For example, if "D" and "P" are similar, and "D" and "G" are similar, "P" and "G" are by definition similar as well.
The first line of input contains a single string $$$s$$$, consisting of only capital letters: the correct text on the eye chart. The next line of input contains a single string $$$t$$$, consisting of only capital letters: your incorrect interpretation of the text on the eye chart. $$$s$$$ and $$$t$$$ are guaranteed to be the same length. The second line of input contains a single positive integer $$$n$$$: the number of letter pairs that you consider to be similar. The next $$$n$$$ lines contain two space-separated capital letters: a letter pair where the first letter is similar to the second, and the second letter is similar to the first.
Output three space separated integers $$$a$$$, $$$b$$$, and $$$c$$$: the number of characters you got right, the number of characters you were close on, and the number of characters you got completely wrong, respectively, according to the definitions above.
DEFPOTEC PEFDOTED 3 D P C D A Z
5 3 0
DEFPOTEC ABCDEFGH 7 A H D H B Z Z Y Y E F C C T
0 4 4
You're in a large maze, and unfortunately the maze is filled with differing amounts of uranium ore, which could potentially expose you to dangerous amounts of radioactivity. Luckily, you have brought your trusty Geiger Counter with you, so you can measure the radioactivity of any given part of the maze in counts per minute (CPM).
You start at the top left corner of the maze, and you are trying to travel to the bottom of the maze. For any path through the maze, its radioactivity value is defined as the maximum CPM across all cell in the maze that you travel through on the path. Your task is to find the path through the maze with the lowest radioactivity value, in other words, find the highest CPM you have to expose yourself to if you travel on the optimal path.
You're allowed to move in any direction (except diagonally), and you can visit the same cell twice (although it is never necessary to).
Note that since the constraints on the size of the maze are fairly large, a brute force (complete search) solution that tries all possible paths,will not work.
The first line of input contains two space-separated positive integers $$$n$$$ and $$$m$$$: the number of rows and columns in the maze, respectively. $$$n$$$ and $$$m$$$ will be less than 100. The next $$$n$$$ lines each contain a string containing $$$m$$$ digits (between 0 and 9), representing the radioactivity of each space in the maze in CPM.
Output a single positive integer: the maximum amount of radioactivity that you have to expose yourself to, if you travel optimally through the maze and minimize this value.
6 8 13567657 24903578 83107213 98829363 25511282 39108443
4
6 5 89888 88898 99998 88888 89999 88888
8
If you aren't sure where to start, try thinking of the maze as a graph.
Also, you should add these two lines to the top of your code if you're going to use recursion in your solution and you're coding in Python:
import sys
sys.setrecursionlimit(20000)
You played against a Man Machine in chess, and because it is a superhuman being, you lost every game. Now, you're trying to practice chess so that you can beat the Man Machine.
To practice, you want to figure out how many different ways there are to place $$$N$$$ queens on an $$$N$$$ by $$$N$$$ chessboard, such that no two queens attack each other (queens can attack any number of spaces directly diagonal, left, right, up, or down). This is called the $$$N$$$-queens problem, and is a standard computer science problem involving recursion and backtracking. Your task is to implement this solution on chessboards where $$$N$$$ can be up to 9.
The only line of input contains a single positive integer $$$N$$$: the size of the chessboard.
Output a single positive integer $$$c$$$: the number of ways to place $$$N$$$ queens on the chessboard, such that no two queens attack each other.
8
92
1
1
If your program consists only of a lookup table with the correct values, your submission will be judged as incorrect and you may be disqualified from the contest.
You are in a hall of mirrors, and you shine a laser beam in a certain direction. Given the position of several diagonal mirrors, figure out the path of the laser beam.
You shine your laser beam from the back of the hall of mirrors (on a computer screen, this will look like the "bottom" of the image).
The first line of input contains two space-separated integers $$$n$$$, $$$m$$$, and $$$x$$$. $$$n$$$ and $$$m$$$ represent the number of rows and columns, respectively, and the number $$$x$$$ represents the index on the bottom row that you start shining the laser pointer at (with 0-based indices). The next $$$n$$$ lines contain $$$m$$$ characters representing the hall of mirrors. If a position does not contain a mirror, it will be pictured as a single dot. If it does have a mirror, it will be represented with either a forward slash ("/") or a backslash, which represents the direction that it reflects light in. See the example cases if you are confused on this.
Output the given input matrix, however, replace any positions without a mirror that the laser pointer shines through horizontally with a hyphen, and replace any positions without a mirror that the laser pointer shines through vertically with a pipe ("|"), above the ENTER key on a keyboard. If the laser pointer travels through a space in both directions, replace the dot in that position with a plus symbol ("+").
10 10 5 .......... .......... /....\.... .......... .......... .......... .......... \......... .......... ..........
.......... .......... /----\.... |....|.... |....|.... |....|.... |....|.... \----+---- .....|.... .....|....
10 10 3 /.\....... ./....\... .......... .......... .\.\...... .......... ..\.../... .......... .......... \.........
/-\....... |/+---\... |||...|... |||...|... |\+\..|... |.||..|... |.\+--/... |..|...... |..|...... \--+------
Drawn an H. You will be given a number the represents the length of the legs and middle portion of the H.
One number representing the dimensions of the H.
Print the H.
3
H H H H H H HHHHH H H H H H H
Much like the previous question, you are going to be making some ASCII art. In this question your job is to make a pyramid given a number that represents the base of the pyramid. Each layer going up from the base should be 2 less in length than the previous layer. The pyramid is complete when the length of the top layer is either 1 or 2.
A single number representing the base of the pyramid.
Print the pyramid using "X"'s
7
X XXX XXXXX XXXXXXX
Don't forget to add spacing on the left side so that it doesn't end up looking like a right triangle.
In this question you must encrypt or decrypt a message by replacing a key letter with a word or a key word with a letter. If the message contains the key word then you should be decrypting and replacing the key word with the key letter. If the message given does not contain the key word then you should be encrypting and should be replacing the key letter with the key word. The key letter will not be within the key word.
The first line will be the text you are encrypting or decrypting. The second line will be the key letter and the third line will be the key word.
Print the encrypted or decrypted text
hello world l bruh
hebruhbruho worbruhd
hebruhbruho worbruhd l bruh
hello world
Converting from one unit of measurement to another is very useful. Make a program that can convert between, feet, inches, meters, centimeters, miles, and kilometers. Use the following conversions to get the correct answer: .08333 feet in 1 inch, 3.28084 feet in 1 meter, 0.0328084 feet in one centimeter, 5280 feet in 1 mile, and 3280.84 feet in 1 kilometer.
One line describing a conversion: Ex: "The road is 1.5 miles, how many kilometers is it."
Print the value of the conversion and the unit.
I am 1.5 meters, how many feet am I
4.92126 feet
The first number and unit will always be right before the ",". after the "," it will always "how many" then the unit you are converting to.
You're flying an airplane, but you forgot to forgot to refill the fuel tank before you trip. Therefore, you must decide which airport to land at based on a number of factors: proximity, available runway space, and direction. If an airport has no available spaces, you cannot go there. If an airport is too far away, you cannot go there.
You will receive 3 lines of input, the first being n number of airports, the second being how many miles you can fly, and the third being the direction of the wind (N,S,W,E,NW,NE,SW,SE). Then you will receive n lines of input consisting of 3 variables separated by spaces: the number of available runway spaces, the distance to the airport in miles, and the direction you must fly to get to the airport.
You will output a number that represents which airport you should fly to.
2 20 S 1 20 S 1 20 N
1
If you are flying with the wind direction, the amount of fuel you need to use is halved. If you are flying against the wind direction, it takes two times as much fuel to get to the airport.
So I think the title explains it. Encrypt a given phrase using the vigenere cipher with a key that will be provided. The vigenere cipher is actually quite easy to use, just look at the image below. The left side is where the plain text characters go and the top is where the key letters go. The first letter of the plain text goes with the first letter of the key and all you do is draw a line across for the plain letter and a line down for the key letter. Where the two lines intersect is the new encrypted letter. Then you pair the second letter of the plain text with the second letter of the key and so on. Once you have reach the last letter of the key, you just go to the start of the key again. Also don't encrypt spaces, so just skip over them.
The first line will be the plain text and the second line will be the key.
Print the newly encrypted text.
Here is an example test case fish
Mmjl na su jfstutw ajal jfaw
In this question your goal is to make a program that will simulate running some pretty basic pseudocode. Here is the syntax that will be used:
Defining a variable: -"var variableName = value" -value can be any integer -value can be a simple math equations ex: "3 + 5" -value can be a simple math equation that includes a variable "testVar + 2"
Manipulating a variable: -"variableName = value" -same rules applied to what the value can be as the one above -Ex: "test1 = test1 + 2 - test2"
Printing: -"print (hello word )+exampleVariable+" -text that is being printed will be surrounded in parentheses -variables being printed will be surrounded in addition signs
The first line will be the number of lines of code. The next X number of lines will be the code that you need to simulate.
Print whatever the program prints.
6 print (hello world) var a = 5 a = a - 1 var b = a + 3 var c = a + b print +a+( + )+b+( = )+c+
hello world 4 + 7 = 11
You consider a string to be a diverse string if every pair of adjacent characters are different. For example coderams is a diverse string, while hello is not.
Given a string, figure out whether or not it is a diverse string.
The only line of input contains a single string, not containing spaces.
If the string is a diverse string, output "YES" (no quotes). Otherwise, output "NO" (no quotes).
coderamsclub
YES
helloworld
NO
You have a list of $$$n$$$ books. You want to read one complete book, but you want to read as few pages as possible. You're given the list of how many pages each book has. Figure out the minimum number of pages that you have to read, reading at least one complete book.
The first line of input contains a positive integer $$$n$$$: the number of books. The next line contains $$$n$$$ space-separated integers: the number of pages of each book.
Output a single positive integer $$$p$$$: the minimum number of pages that you have to read, if you read at least one complete book.
5 179 173 275 865 180
173
5 500 450 300 299 100
100
In computer graphics, colors are often given as three integers $$$R$$$, $$$G$$$, and $$$B$$$, each ranging from 0 to 255, inclusive.
When displaying a bright red color, $$$R$$$ = 255, $$$G$$$ = 0, and $$$B$$$ = 0.
When displaying a bright green color, $$$R$$$ = 0, $$$G$$$ = 255, and $$$B$$$ = 0.
When displaying a bright blue color, $$$R$$$ = 0, $$$G$$$ = 0, and $$$B$$$ = 255.
When displaying a bright yellow color, $$$R$$$ = 255, $$$G$$$ = 255, and $$$B$$$ = 0.
Given this information, figure out which color corresponds to a RGB-format color given in the input.
The only line of input contains three space-separated integers $$$R$$$, $$$G$$$, and $$$B$$$: the values of $$$R$$$, $$$G$$$, and $$$B$$$ as described above.
Output a single string: the color that the input values would display when drawn on a computer screen.
If the color is red, output "RED" (no quotes)
If the color is green, output "GREEN" (no quotes)
If the color is blue, output "BLUE" (no quotes)
If the color is yellow, output "YELLOW" (no quotes)
255 0 0
RED
255 255 0
YELLOW
You recently performed well in an online Codeforces contest, and you became part of "Division 1" on Codeforces. However, you're not sure that it will last. If you have a rating of 1900 or higher you're considered Division 1, otherwise, you're considered Division 2.
In each contest after you became Division 1, you didn't perform very well. Thus, your rating will decrease by 50 in each contest. Given your start rating, figure out how many contests it will take for you to become Division 2.
For example, if your start rating was $$$1970$$$, your rating would be $$$1920$$$ after the first contest, and after the second contest your rating would be $$$1870$$$, and you would become Division 2.
The only line of input contains a single positive integer $$$n$$$: your rating after the recent good contest.
Output a single positive integer $$$c$$$: the number of contests that you can still do before you become Division 2.
1970
2
2035
3
3549
33
Your 5-year-old cousin from the CodeRams Contest #5 (Problem 4) is now in 4th grade, and he is learning how to simplify fractions. Unfortunately, he doesn't really understand them, and he needs your help in simplifying fractions.
For this problem, you must write a program to convert a fraction $$$a$$$/$$$b$$$ to simplest form. For example, if the fraction was $$$6$$$/$$$8$$$, you can factor out a $$$2$$$, and the fraction simplifies to $$$3$$$/$$$4$$$, which is in simplest form.
The only line of input contains a single fraction $$$a$$$/$$$b$$$: the fraction you need simplify. $$$a$$$/$$$b$$$ can be greater than one, but $$$a$$$ will not be a multiple of $$$b$$$. So $$$3$$$/$$$2$$$ would be a valid input, but $$$6$$$/$$$2$$$ would not.
Output a single fraction $$$c$$$/$$$d$$$ in the same format as the input: the input fraction, in simplest form, as described above.
6/8
3/4
72/48
3/2
37/73
37/73
In this problem, the input will be small enough for a brute force solution that tries all factors to run efficiently.
You're traveling through space in your spaceship, when your ship's radar detects several hostile aliens near the ship. You need to figure out how close each alien is to your ship.
In three dimensions, the distance between two points, each with an X, Y, and Z coordinate, is defined as follows:
Given the coordinates of your ship, in 3D space, figure out how far away each alien is from your ship, using the formula described above.
The first line of input contains three space-separated integers $$$X$$$, $$$Y$$$, and $$$Z$$$: the coordinates of your ship in 3D space. The next line of input contains a positive integer $$$n$$$ indicating the number of aliens that have been detected by the ship's radar. The next $$$n$$$ lines each contain three space-separated integers, each representing the coordinates of an alien.
Output $$$n$$$ lines. On each line, output a single decimal number: the distance between your ship and each alien, in the order given in the input. You don't need to round your answers.
7 3 8 6 2 1 5 3 7 6 4 2 1 9 8 4 7 3 8 5 11 16
6.164414002968976 6.0 7.681145747868608 6.708203932499369 0.0 11.489125293076057
2 4 6 3 -2 -4 -6 2 -4 -6 -2 4 6
14.966629547095765 14.422205101855956 4.0
You're phone has incorrectly autocorrected some of your recent texts, and you're trying to make a more effective autocorrect system.
You're given an incorrectly spelled word. The similarity index of two words $$$s$$$ and $$$t$$$ is calculated as follows:
1. Define two variables: $$$tot$$$, representing the total pairs checked, and $$$mat$$$, representing the matches found.
2. Iterate through all pairs of letters in $$$s$$$ and $$$t$$$.
3. Increment $$$tot$$$ by one, and if the letters are equal, increment $$$mat$$$ by one as well.
The similarity index is calculated as mat / tot.
Given several words, your autocorrect system will choose the word which is the most similar to the original word, using the algorithm described above.
The first line of input contains a single word $$$w$$$: the incorrectly spelled word, consisting only of lowercase characters. The next line contains a single positive integer $$$n$$$: the number of correctly spelled words in the dictionary. The next $$$n$$$ lines each contain a correctly spelled word $$$s$$$: a dictionary entry, consisting of only lowercase characters.
Output $$$n$$$ lines. Each line should contain a word from the dictionary, and its similarity index, rounded to two decimal places. The words should be sorted from highest to lowest by their similarity index. If two words have the same similarity index, sort them alphabetically in reverse order.
hello 5 helo helllo yello hellow helpo
helllo 0.30 helo 0.25 yello 0.24 hellow 0.23 helpo 0.20
coderams 8 cauliflower coders codered classroom codeforces contest code coding
coders 0.12 codered 0.12 code 0.12 codeforces 0.11 classroom 0.11 contest 0.07 coding 0.06 cauliflower 0.06
You're trying to come up with a good Codeforces username. You want to use something similar to your real name, but not exactly your real name, to not release too much info about yourself online. Thus, you decide to encode your username using an Affine cipher.
An affine cipher uses a key of two values: $$$a$$$ and $$$b$$$. Given a letter $$$l$$$, you first convert it into it's "character code", for example, "a" would become $$$0$$$, "b" would become $$$1$$$, etc. We'll call this $$$x$$$. Then, you calculate the value of $$$a$$$$$$x$$$ + $$$b$$$ mod $$$26$$$, and reverse the character code mapping that you used previously, to convert the answer back into a letter. The affine cipher runs this process on all letters (not spaces) in a given string.
For example, let's use the letter $$$c$$$, and a key of $$$a$$$ = $$$15$$$, and $$$b$$$ = $$$5$$$. $$$c$$$ has a character code of $$$2$$$. Then, the encoded character has a character code of $$$15$$$*$$$2$$$ + $$$5$$$ mod $$$26$$$ = $$$35$$$ mod $$$26$$$ = $$$9$$$. Thus, the encoded character is $$$j$$$.
The first line of input contains two space-separated integers $$$a$$$ and $$$b$$$: the affine cipher's key, as described above. The second line of input consists of a string consisting only of lowercase characters and spaces.
Output the input string, encoded using the affine cipher as described above.
7 5 xavier
kfwjhu
11 1 coderams club
xzitgbdr xsnm
You attended the final stage of the Tour De France, and after the event has ended, you want to know the final results. However, all you know is how long it took each biker to reach your position, and how fast they were traveling when they passed you.
Given your constant position during the race, the position of the finish line, and the information described above, you must figure out the final standings of the race. You can assume that after each biker passed you, they maintained a constant speed.
The first line of input contains three space-separated integers $$$n$$$, $$$m$$$, and $$$k$$$, representing the number of bikers in the race, your position, in miles, and the position of the finish line, in miles, respectively. The next $$$n$$$ lines each contain a string representing each biker's name, and a space, followed by two space-separated decimal numbers, representing the time that the biker passed by you, in seconds, and the biker's speed, in miles per hour, respectively.
Output $$$n$$$ integers: each biker's name, sorted by their overall place in the race. The biker that finished first should be first in the list, and the biker that finished last should be last in the list.
5 10 25 CadelEvans 20 30 BradleyWiggins 21 29 ChrisFroome 22 31 VincenzoNibali 25 80 GeraintThomas 5 17 EganBernal 8 21
GeraintThomas CadelEvans BradleyWiggins ChrisFroome VincenzoNibali
This problem was originally made for the contest where all of the problems were based on Kraftwerk songs. It was removed from the contest beforehand for various reasons.
You're listening to music, and you hear a major chord of three notes. You want to figure out which chord you just heard.
In music, the notes in a single octave, from lowest to highest, are as follows: C, C#, D, D#, E, F, F#, G, G#, A, A#, and B. Any two adjacent notes in this list are a "half step" apart. For example, C and D differ by 2 half steps, and A and D differ by 5 half steps.
Additionally, notes can be represented as both sharps and flats. For example, C# and D ♭ (D flat) are the same note, and D# and E ♭ are the same note. A flat note will be represented with a lowercase f in the input, such as "Df" for D flat.
A major chord has a $$$root$$$, a $$$third$$$ note, and a $$$fifth$$$ note. The root and the third note must differ by exactly four half steps, and the third and fifth note must differ by exactly three half steps. Correspondingly, the root and the fifth note must differ by exactly seven half steps.
Given this information, and a major chord, figure out what the root of the chord is. The notes of the chord can be given in any order, i.e. the root doesn't necessarily come first.
The only line of input contain three space-separated notes. It is guaranteed that the notes form a major chord with the root being one of the three notes.
Output a single note: the root of the chord.
E G C
C
Bf Ef G
Ef
C F A
F
C# F Af
C#
You're going to a city that has a large subway system. The subway system has $$$n$$$ lines, and each line has a certain number of stations. However, some stations are "transfer stations": multiple lines go through them.
Given a list of the stations that each subway line goes through, your task is to figure out how many transfer stations exist throughout the subway system.
Note that "loop lines" that start and end at the same station may appear in the input, and stations that are the start and end of the loop but have no other lines going through them do not count as transfer stations. For a station to be a transfer station, it has to have multiple distinct lines going through it.
The first line of input contains a single positive integer $$$n$$$: the number of lines in the subway system.
The next $$$n$$$ test cases each consist of two lines of input.
The first line consists of a single positive integer $$$m$$$: the number of stations in the given subway line
The next line contains $$$m$$$ space-separated station names, representing the route of the given subway line. The subway line might be a loop line.
Output a single positive integer $$$s$$$: the number of transfer stations in the subway system. Then, output $$$s$$$ station names: the name of each transfer station in the subway system, in alphabetical order.
6 7 Vienna EastFallsChurch Rosslyn MetroCenter LenfantPlaza StadiumArmory NewCarrolton 7 WiehleRestonEast EastFallsChurch Rosslyn MetroCenter LenfantPlaza StadiumArmory LargoTownCenter 8 FranconiaSpringfield KingStOldTown Pentagon Rosslyn MetroCenter LenfantPlaza StadiumArmory LargoTownCenter 5 BranchAvenue LenfantPlaza GalleryPlace FortTotten Greenbelt 6 Huntington KinStOldTown Pentagon LenfantPlaza GalleryPlace FortTotten 5 ShadyGrove MetroCenter GalleryPlace FortTotten Glenmont
EastFallsChurch FortTotten GalleryPlace LargoTownCenter LenfantPlaza MetroCenter Pentagon Rosslyn StadiumArmory
3 5 EastStation NorthStation WestStation SouthStation EastStation 2 WestStation CenterStation 2 NorthStation CenterStation
CenterStation NorthStation WestStation
Can you figure out which city has the subway system described in the first test case?
A latin square is defined as a 4 by 4 grid of numbers, where all of the numbers in each row and column are distinct, i.e. no two pairs of elements in each row and column are equal.
You're given a partially filled in latin square. Figure out how many valid latin squares can be formed by filling in the empty digits of the latin square.
The input consists of 4 lines, each consisting of 4 integers: the digits in the latin square. For each digit, if it has already been filled in, it will be represented with a digit from 1 to 4, and if it hasn't been filled in yet, it will be represented with a "0".
Output a single positive integer $$$n$$$: the number of ways to fill in the latin square as described above.
0000 0000 0000 0000
576
1234 2341 3412 0000
1
1234 2341 3412 4311
0
Your 5-year-old cousin from the CodeRams Contest #5 (Problem 4) is now in 4th grade, and he is learning how to add fractions. Unfortunately, he doesn't really understand them, and he needs your help in adding two or more fractions together.
For this problem, you must write a program to add several positive fractions together.
Since the test cases can be large, you will need to use an efficient method to solve it.
When adding two fractions together, you first change the denominators into their LCM (least common multiple).
The LCM of two numbers $$$a$$$ and $$$b$$$ can be calculated using the following formula:
LCM($$$a$$$, $$$b$$$) = $$$\frac{a * b}{GCD(a, b)}$$$, where GCD represents the greatest common divisor of $$$a$$$ and $$$b$$$.
You can find the greatest common divisor (GCD) or $$$a$$$ and $$$b$$$ efficiently using the following recursive algorithm:
1. If $$$a$$$ is less than $$$b$$$, swap $$$a$$$ and $$$b$$$
2. If $$$b$$$ is equal to $$$0$$$, return $$$a$$$
3. Otherwise, return GCD($$$b$$$, $$$a$$$ mod $$$b$$$)
The only line of input consists of a mathematical operation involving at least two fractions, each in the form $$$a$$$/$$$b$$$, and addition operations only
If the answer simplifies to a whole number, print the number. Otherwise, output a single fraction $$$c$$$/$$$d$$$: the result of the addition of fractions described in the input, in simplest form. The answer will not be less than or equal to 0.
3/4 + 2/3 + 7/9
79/36
8/7 + 8/9 + 17/11 + 33/53 + 89/77 + 65/59
13993216/2167011
2/3 + 7/3
3
If your code passes the second example case in under a second, it is efficient enough. Also, all input and output numbers are guaranteed to fit inside of an "int" data type in Java, if you code your solution efficiently.
You're play a modified version of Conway's Game of Life on a 2D grid. Each cell on the grid can be represented as three states:
An asterisk, representing a cell that is "alive"
A period, representing a cell that is "dead"
An uppercase X, representing a "barrier".
On each turn, cells change their state depending on the following rules:
1. If the cell is not a barrier and is adjacent to any dead cells, the cell becomes a dead cell
2. If the cell is a barrier, is adjacent to only barriers, and is not on the edge of the board, it becomes a dead cell
Note that in these definitions, "adjacent to" refers to all 8 of the spaces next to a cell, including diagonally. Also note that all of the changes to cells take effect after the current turn, so the order that you apply the operations in doesn't matter.
It can be shown that if played infinitely many times, this (simplified) version of Conway's Game of Life will eventually converge on a single board state, i.e. the board will eventually never change between turns. Given a starting board, figure out the final state of the board if played infinitely many times.
The first line of input contains two positive integers $$$n$$$ and $$$m$$$: the number of rows and columns, respectively. The next $$$n$$$ lines each contain $$$m$$$ characters, each representing a cell of the board, according to the rules above.
Output a $$$n$$$ by $$$m$$$ board in the same format as the input: the final state of the board, after running the algorithm infinitely many times.
6 6 *****X ****XX **XXX. **XXX. **XXX. XXX..*
*****X ****XX **XXX. **X.X. **XXX. XXX...
6 6 *****X *.**XX **XXX. **XXX. **XX.. XXX...
.....X ....XX ..XXX. ..XXX. ..XX.. XXX...
3 4 XXXX XXXX XXXX
XXXX X..X XXXX
You're playing Minecraft, and having fun exploring your world in Creative mode. Your world consists of Desert, Forest, and Taiga biomes.
You've explored some of the world, but not all of it. Thus, for some places, you know their biome, and for others, you don't. The world is given as a 2D top-down view, with some spaces ("chunks") unknown, and others with a known biome.
You especially like Taiga biomes. You've already explored at least one space that is a taiga biome, and you know that your world has exactly one taiga biome. Given this information, your task is to figure out the maximum amount of spaces (chunks) on the 2D world map that can be part of a taiga biome, and which spaces could potentially be part of the taiga biome.
Two spaces are considered part of the same biome if you can travel on the 2D grid from one space to the other, traveling on only spaces of the given biome. For example, if two spaces are both in Taiga biomes, but to travel from one to the other you are forced to cross a desert, they are not part of the same biome.
The input consists of 20 lines, each containing 20 characters: the 20 by 20 world map.
If a given space is part of a Taiga biome, it will be represented by a "T" in the input file.
If a given space is part of a Desert biome, it will be represented by a "D" in the input file.
If a given space is part of a Forest biome, it will be represented by an "F" in the input file.
If you haven't explored a certain space, it will be representing as a single dot (".") in the input file.
Output 20 lines: the given input, except if any unexplored spaces (chunks) could potentially be part of a Taiga biome, change their character to a "T".
.................... .................... .................... .........T.......... .................... .................... .................... .................... .................... FFFFFF.F............ ......F.F....FFFFFFF .........F.......... ..........FF........ .....DDDD....DDDD... ........DDDDDD...DDD DDDDDDDD............ .................... .................... .................... ....................
TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT FFFFFFTFTTTTTTTTTTTT TTTTTTFTFTTTTFFFFFFF TTTTTTTTTFTTTTTTTTTT TTTTTTTTTTFFTTTTTTTT TTTTTDDDDTTTTDDDDTTT TTTTTTTTDDDDDD...DDD DDDDDDDD............ .................... .................... .................... ....................
.................... .................... .................... .........T.......... .................... .................... .................... .................... .................... FFFFFF.F............ ......F.F....FFFFFFF .........F..F....... ..........FF........ .....DDDD....DDDD... ........DDDDDD...DDD DDDDDDDD............ .................... .................... .................... ....................
TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT TTTTTTTTTTTTTTTTTTTT FFFFFFTFTTTTTTTTTTTT ......F.FTTTTFFFFFFF .........FTTF....... ..........FF........ .....DDDD....DDDD... ........DDDDDD...DDD DDDDDDDD............ .................... .................... .................... ....................
.................... .................... .........DDDD....... ........DTD...D..... ........DDDDD....... .................... .................... .................... .................... FFFFFF.F............ ......F.F....FFFFFFF .........F.......... ..........FF........ .....DDDD....DDDD... ........DDDDDD...DDD DDDDDDDD............ .................... .................... .................... ....................
.................... .................... .........DDDD....... ........DTD...D..... ........DDDDD....... .................... .................... .................... .................... FFFFFF.F............ ......F.F....FFFFFFF .........F.......... ..........FF........ .....DDDD....DDDD... ........DDDDDD...DDD DDDDDDDD............ .................... .................... .................... ....................
If you competed in the CodeRams Contest #8, you might remember a problem involving mirrors and light. This is a more difficult and updated version of that problem.
You are in a hall of mirrors, and you shine a laser beam in a certain direction. Given the position of several diagonal mirrors, figure out the path of the laser beam.
You shine your laser beam from the back of the hall of mirrors (on a computer screen, this will look like the "bottom" of the image).
This problem also adds "star blocks", which shine light in all directions when light passes through them.
The first line of input contains two space-separated integers $$$n$$$, $$$m$$$, and $$$x$$$. $$$n$$$ and $$$m$$$ represent the number of rows and columns, respectively, and the number $$$x$$$ represents the index on the bottom row that you start shining the laser pointer at (with 0-based indices). The next $$$n$$$ lines contain $$$m$$$ characters representing the hall of mirrors. If a position does not contain a mirror, it will be pictured as a single dot. If it does have a mirror, it will be represented with either a forward slash ("/") or a backslash, which represents the direction that it reflects light in. See the example cases if you are confused on this. Additionally, if the position contains a star block, it will be pictured as an asterisk ("*"). Star blocks redirect light in all four immediate directions (up, down, left, and right).
Output the given input matrix, however, replace any positions without a mirror or star block that the laser pointer shines through horizontally with a hyphen, and replace any positions without a mirror or star block that the laser pointer shines through vertically with a pipe ("|"), above the ENTER key on a keyboard. If the laser pointer travels through a space in both directions, replace the dot in that position with a plus symbol ("+").
10 10 5 ......./.. .......... /....\.... .......... .......... .......... .......... \......*.. .......... ..........
......./-- .......|.. /----\.|.. |....|.|.. |....|.|.. |....|.|.. |....|.|.. \----+-*-- .....|.|.. .....|.|..
10 10 2 ../....\.. .......... /.*..\.... .......... .......... .......... .......... \......*.. .......... ..........
../----\.. ..|....|.. /-*--\.|.. |.|..|.|.. |.|..|.|.. |.|..|.|.. |.|..|.|.. \-+--+-*-- ..|..|.|.. ..|..|.|..
You have a function $$$f(x)$$$, and you want to figure out how the area under $$$f(x)$$$ from 0 to $$$C$$$.
In calculus, this value is called the $$$integral$$$ of $$$f(x)$$$. For some functions, taking its integral is relatively easy and uses a few simple rules. However, for many functions, it is impossible to find their integral exactly. However, you can make an approximation of the integral, and since you're writing a computer program, you can make a close approximation.
One way to approximate the integral of a function is to use the Rectangular Approximation Method, or RAM. This method approximates the function $$$f(x)$$$ as $$$n$$$ rectangles, each having an equal width, and having varying $$$y$$$-values depending on the value of $$$f(x)$$$ at that point.
As you can see, the example with $$$n$$$=4 ($$$f(x)$$$ was divided into four rectangles) was not perfect. However, as $$$n$$$ gets larger and larger, the approximations get more and more accurate.
Formally, define the LRAM (Left Rectangular Approximation Method) approximation of the area under a function $$$f(x)$$$ from $$$0$$$ to $$$C$$$, using $$$n$$$ rectangles, as A, and the area of each rectangle as A1, A2 ... AN, as the following:
A = $$$\frac{A1 * C}{N}$$$ + $$$\frac{A2 * C}{N}$$$ + $$$\frac{A3 * C}{N} $$$+ ... + $$$\frac{AN * C}{N}$$$.
The area of each rectangle can be calculated using the standard formula A = $$$l$$$ x $$$w$$$. The width of each subrectangle is equal to $$$\frac{C}{n}$$$ (because there are $$$n$$$ rectangles with a total width of $$$C$$$). The length of each subrectangle is equal to $$$f(\frac{k * c}{n})$$$, where $$$k$$$ represents the index of the rectangle, ranging from $$$0$$$ to $$$n - 1$$$, inclusive.
Since your answer must be a relatively close approximation, but your program should fit inside of the 10 second time limit (longer than usual for this problem), you should set $$$N$$$ equal to 50000.
The only line of input contains a calculus equation. The equation will consist of the variable $$$x$$$, exponents, parentheses, and multiplication, division, addition, and subtraction operations. For example, $$$\frac{x^2 - 3}{x^3 - x + 5}$$$ would be a valid input, but $$$cos(x)$$$ would be not.
Output a single decimal number: the area under $$$f(x)$$$ from $$$x$$$=$$$0$$$ to $$$x$$$=$$$C$$$. Your number should be close to the actual answer, but it doesn't have to be exact. Using eval() or similar commands in your program is not allowed.
x^3 + x^2 2
6.666426668800027
(x^2 + x + 3) / (x^3 + x^2 + 5x) 7
0.9806709605550483
x^2 5
41.66541667500017
In the first sample case, $$$6.663$$$ would be judged as correct, but $$$7$$$ would be judged as incorrect.
You consider a string to be a question if its last character is a question mark. Given a string, figure out whether or not it is a question.
The only line of input contains a single string $$$s$$$.
If the given string is a question (if it has a question mark on the end), output "YES" (no quotes). Otherwise, output "NO" (no quotes).
Welcome to the CodeRams contest?
YES
We hope you like the problems!
NO
Good luck today
NO
You define a string to be an alarming string if it contains exactly three "a" characters. Given a string, possibly containing spaces, figure out whether or not it is an alarming string.
The only line of input contains a single string $$$s$$$, consisting of only lowercase characters.
Output "YES" (no quotes) if the given string is an alarming string, as described above, and "NO" (no quotes) otherwise.
coderams competition number eleven
NO
aardvark
YES
an apple actually appeared
NO
You're given a list of $$$n$$$ words. You've discovered that when a rival CodeQuest team finds a list of words, they sort it in alphabetical order. To distinguish yourself from your rival CodeQuest team, you decide to sort the list of words in reverse order.
The first line of input contains a single positive integer $$$n$$$: the number of words.
The next $$$n$$$ lines each contain a single word, consisting only of lowercase letters
Output $$$n$$$ lines: the list of words, sorted in reverse alphabetical order.
2 coderams club
coderams club
11 hello world we hope you enjoy the contest today good luck
you world we today the luck hope hello good enjoy contest
You're competing in a large individual math team contest. In the contest, you're given several sets of problems, and for each one of them you get a certain number of them correct. Given this information, you want to figure out your total score in the competition.
For example, if you scored a 2 out of 3 on the first problem set, and a 3 out of 5 on the second problem set, your total score would be 5 out of 8.
The first line of input contains a single positive integer $$$n$$$: the number of problem sets.
The next $$$n$$$ lines contain two integers separated by a slash "/": the number of questions you got right in the problem set, and the total number of questions in the problem set.
Output two slash-separated integers: the total number of questions you got right, and the total number of question you got wrong, respectively.
5 2/5 4/6 8/11 3/8 1/9
18/39
5 6/6 5/6 3/6 0/6 5/8
19/32
You consider a number to be cheesy if it is divisible by the sum of its digits. For example, the sum of the digits of 360 is 9, and 360 is divisible by 9, so 360 is a cheesy number. On the other hand, the sum of digits of 87 is 15, and 87 is not divisible by 15, so 87 is not a cheesy number.
Given a number $$$n$$$, figure out whether or not it is a cheesy number.
The only line of input contains a single integer $$$n$$$: the number to test. $$$n$$$ is guaranteed to fit inside of an "int" data type in Java.
If $$$n$$$ is a cheesy number as described above, output "YES" (no quotes). Otherwise, output "NO" (no quotes).
360
YES
87
NO
72
YES
A number is considered a perfect number if and only if the sum of its divisors, except for the number itself, is equal to the original number. For example, 28 is a perfect number because its divisors are $$$1$$$, $$$2$$$, $$$4$$$, $$$7$$$, and $$$14$$$, and $$$1$$$ + $$$2$$$ + $$$4$$$ + $$$7$$$ + $$$14$$$ = $$$28$$$.
Given an integer $$$n$$$, figure out whether or not it is a perfect number, and what the sum of its divisors (except for $$$n$$$) is.
The only line of input consists of a single integer $$$n$$$.
Output two lines.
On the first line, output "PERFECT NUMBER" (no quotes) if the number is a perfect number, and "NOT A PERFECT NUMBER" (no quotes) if the number is not a perfect number. On the second line, output the sum of divisors of the number.
28
PERFECT NUMBER 28
48
NOT A PERFECT NUMBER 76
All numbers used in calculations are guaranteed to fit inside of a Java "int" data type.
Your computer outputs $$$n$$$ integers randomly. You think it might be a secret code, so you decide to make a list of the numbers, but maintain the list in sorted order as you add each number.
For example, if the computer output was $$$3$$$ $$$4$$$ $$$2$$$ $$$8$$$ $$$7$$$, you would first add $$$3$$$ to the list, making the list [3].
Then, you would add $$$4$$$ to the list, making the list [3, 4].
Then, you add $$$2$$$, putting it first in the list to maintain the list's sorted order. The list becomes [2, 3, 4]
The process proceeds until the list is [2, 3, 4, 7, 8] after the final step.
The first line of input contains a positive integer $$$n$$$: the amount of numbers your computer has printed out.
The next $$$n$$$ lines contain $$$n$$$ integers: the numbers that your computer printed out.
Output $$$n$$$ lines. On the $$$k$$$th line, output $$$k$$$ integers: the sorted list after adding the $$$k$$$th number from the computer's output to the list.
5 3 4 2 8 7
3 3 4 2 3 4 2 3 4 8 2 3 4 7 8
You're eating at a continental breakfast in a hotel, and there are two menu options. Each menu option consists of several food items. You want to find how many food items are contained in both menus.
The first line of input consists of a single positive integer $$$n1$$$: the number of food items on the first menu. The second line of input consists of $$$n1$$$ space-separated strings: the food items on the first menu.
The third line of input consists of a single positive integer $$$n2$$$: the number of food items on the second menu. The fourth line of input consists of $$$n2$$$ space-separated strings: the food items on the second menu.
Output a single positive integer $$$n$$$: the number of food items that are contained on both menus. Then, output $$$n$$$ lines: each food item which is contained on both menus, in alphabetical order.
3 Pastries Waffles Eggs 4 Waffles FrenchToast Eggs Cereal
2 Eggs Waffles
3 Eggs Waffles Pastries 2 FrenchToast Cereal
0
You define a string to be a majestic string if each successive character in the string comes one character later in the alphabet than the one before it. For example, bcdef is a majestic string, and so is xyz, but acd is not a majestic string. The characters also wrap from z to a, so yzab is a majestic string.
Given a string $$$s$$$, figure out whether or not it is a majestic string, using the rule described above.
The only line of input contains a single string $$$s$$$.
If $$$s$$$ is a majestic string, output "YES" (no quotes). Otherwise, output "NO".
cdefghij
YES
tuvwxyzab
YES
hellllo
NO
You have a tree that is growing very fast. At first, the tree has one branch. On each successive day, the tree grows a certain number of branches. On each day, the number of new branches is calculated as $$$n$$$ times $$$b$$$, where $$$b$$$ represents how many branches were on the tree on the previous day, and $$$n$$$ is a variable you have to calculate. $$$n$$$ will always be greater than one.
At an unknown number of days, the tree has $$$x$$$ branches. Given this value, figure out the minimum possible value of $$$n$$$ used in the formula, given that the tree started out with exactly one branch.
The only line of input contains a single positive integer $$$x$$$. $$$x$$$ will be less than 10000.
Output a single positive integer $$$n$$$: the minimum possible value of $$$n$$$, greater than one, such that the tree could have $$$x$$$ branches at some point. $$$n$$$ has to stay the same throughout the entire process of growing the tree, i.e. it cannot change between days.
36
5
66
65
You're attending an international Zoom call during the Coronavirus quarantine, where the attendees represent many different countries. The zoom call is really long, and to pass the time, you tally how many people are from each country.
Given the list of people and their countries, print the countries, and how many meeting attendees are from each country. Sort the countries first by their number of attendees, and if two countries have an equal number of attendees, sort them alphabetically by the name of the country.
The first line of input contains a single positive integer $$$n$$$: the number of meeting attendees.
The next $$$n$$$ lines each contain a single country name $$$c$$$.
If there are less than five lines of input, output $$$n$$$ lines: each country, and it's number of meeting attendees, separated by a space.
Otherwise, output 5 lines: each of the top 5 countries using the sorting method described above, and it's number of meeting attendees, separated by a space.
11 USA Sweden Argentina Cameroon Egypt Australia England France Russia Mongolia India
Argentina 1 Australia 1 Cameroon 1 Egypt 1 England 1
4 USA USA Mexico Mexico
Mexico 2 USA 2
9 USA Germany Brazil China USA China China USA USA
USA 4 China 3 Brazil 1 Germany 1
You have a triangle with three points given in coordinates. Given this information, figure out the triangle's area. The points can be given in any order.
To calculate the area of a triangle, you can use Heron's Formula, which is described below:
Define $$$A$$$, $$$B$$$, and $$$C$$$ to be the lengths of the three sides of the triangle.
Define $$$S$$$ to be equal to $$$\frac{A + B + C}{2}$$$.
Then, the area of the triangle is calculated as $$$\sqrt{S(S - A)(S - B)(S - C)}$$$.
The input consists of three lines, each consisting of two space-separated integers $$$x$$$ and $$$y$$$: the coordinates of each point of the triangle.
Output a single decimal number $$$a$$$: the area of the triangle, using Heron's Formula as described above. Do not round your answer.
1 1 5 4 2 8
12.5
0 0 8 0 4 8
32.0
-1 -3 2 7 9 -11
62.0
This triangle corresponds to the first example case:
You've traveled across a galaxy far, far away, and you land on a planet with two different alien species. Each alien species counts numbers in a different base. Aliens of the first species count numbers using base $$$a$$$, and aliens of the second species count numbers using base $$$b$$$. The base used by most humans is decimal, base 10.
The two alien species are about to start a war, because they cannot properly communicate in numbers. Your task is to convert a number from the first alien species, in base $$$a$$$, into base $$$b$$$, in order to avert the impending alien war.
The first line of input contains two integers $$$a$$$ and $$$b$$$ less than or equal to 10: the number base used by the first alien species, and the number base used by the second alien species, respectively.
The second line of input contains a single integer $$$n$$$ in base $$$a$$$.
Output $$$m$$$: the given integer, converted from base $$$a$$$ to base $$$b$$$.
7 9 63642
23550
10 3 8790971
121112121221112
5 6 3124
1530
You're standing in a large 2D grid. The grid consists of several gold blocks. The gold is highly sought after , so for each position in the grid you want to calculate how many steps it would take to walk to the nearest gold block. You can walk left, right, up, or down, but not diagonally.
The first line of input contains a single integer $$$n$$$: the size of the square grid.
The next $$$n$$$ lines each contain $$$n$$$ characters, representing the status of each position in the grid. If the position contains a gold block, it will be represented with an "X". If the position doesn't contain a gold block, it will be represented with a single dot ".".
Output $$$n$$$ lines: the board, after making a few modifications:
Positions with gold blocks should remain an "X".
Positions without gold blocks that are under 10 blocks away from the nearest gold block in walking distance should be represented by their walking distance to the nearest gold block.
Otherwise, positions without gold blocks that are at least 10 blocks away from the nearest gold block in walking distance should remain a single dot ".".
10 .......... ....X..... .......... ..X....X.. .......... .......... ..X....... .......... .......... ..........
5432123345 4321X12234 3212122123 21X1221X12 3212332123 3212343234 21X1234345 3212345456 4323456567 5434567678
10 .......... .......... .......... .......... .......... .......... .......... .......... .......... .........X
.........9 ........98 .......987 ......9876 .....98765 ....987654 ...9876543 ..98765432 .987654321 987654321X
This is a sigificantly harder version of a previous problem in the contest. We recommend you solve the earlier problem first.
You're given the coordinates of an $$$n$$$-sided polygon. The polygon is not necessarily a regular polygon (the sides and angles are not necessarily equal), but the polygon is guaranteed to be convex (the polygon will not contain any angles greater than or equal to 180 degrees).
Given this information, figure out the area of the given polygon.
The first line of input consists of a positive integer $$$n$$$ greater than three: the number of sides of the polygon.
The next $$$n$$$ lines each contain two space-separated integers: the $$$x$$$ and $$$y$$$ coordinates of each point of the polygon.
None of the sides of the polygon will be completely vertical.
Output a single decimal number $$$a$$$: the area of the given $$$n$$$-sided polygon. Remember, the polygon is guaranteed to be a convex polygon.
4 0 5 5 0 0 -5 -5 0
50.0
5 6 6 4 3 2 1 1 5 3 7
15.5
4 1 1 2 3 3 6 4 9
1.0
It might help to use your code from the easier version
You have a string, consisting of at most seven characters, not including spaces. You want to find all of the anagrams of the string. A string $$$t$$$ is defined as an anagram of a string $$$s$$$ if an only if the characters of $$$s$$$, in sorted order, not including spaces, are equal to the characters of $$$t$$$, in sorted order, not including spaces.
You're also given a dictionary of $$$n$$$ words.
An anagram is considered a valid anagram if it consists of only space-separated words that are in the dictionary. For example, if the dictionary was the English dictionary, hello and hello world would be valid anagrams, but he llo and helloworld would not be valid anagrams.
Given the string, and the dictionary, print all of the valid anagrams of the string, in alphabetical order.
The first line of input contains a single string $$$s$$$, possibly containing spaces. $$$s$$$ will have less than or equal to seven characters, not including spaces.
The next line of input consists of a single positive integer $$$n$$$, indicating how many words are in the dictionary.
The next $$$n$$$ lines each contain a word not containing spaces: each dictionary entry.
Output all of the words or phrases that are valid anagrams of the given string, in alphabetical order. Make sure not to repeat words, i.e. all of the answers should be distinct.
coderam 12 arm codes dore smac do res mac armcodes blahblah coderam rams code
arm code code arm coderam dore mac mac dore
hello 5 he ll o hel lo
he ll o he o ll hel lo ll he o ll o he lo hel o he ll o ll he
For this problem, you will be given two side lengths of a triangle and will be required to determine the length of the other side. You can assume that all input will be provided for a valid right triangle. The two side lengths you will be given correspond to the common variables $$$A$$$ and $$$C$$$, meaning one side and the hypotenuse. You should then output the length of side $$$B$$$.
Two space-separated integer values that represent $$$A$$$ and $$$C$$$ respectively.
A single floating point value that represents the length of side $$$B$$$.
9 10
4.358898943540674
Make sure that you are finding the length of side $$$B$$$ and not $$$C$$$(the hypotenuse).
Your task for this problem is to take the three side lengths of a triangle and to determine if these side lengths could create a "valid" triangle. A triangle is considered valid if the addition of any two side lengths is less than the length of the other side, in other words, the following must evaluate to true: a+b>c, a+c>b, b+c>a.
The first line contains three space separated integers that correspond to the lengths of sides a, b, and c respectively.
Output either "VALID" or "INVALID" depending on if the provided side lengths create a valid or invalid triangle.
1 5 1
INVALID
4 5 6
VALID
For this problem, you will be asked to solve specified trigonometry problems. You will be given individual problems that contain sin,cosine,tangent,cosecant,secant, and cotangent. Each test case will specify which operation should be used, using the following keywords: "sin,cos,tan,cosec,sec,cotan". Each test case will also provide the value that should be input into the various trigonometry functions. Your program should output the result of each computation.
The first line contains a keyword of the format "sin,cos,tan,cosec,sec,cotan" that signifies which operation should be computed. The second line contains a floating point value that acts as the input to the trigonometry equation.
A single floating point value that represents the computation of the input with the given trigonometry equation.
sin 2
0.9092974268256817
The Unit Circle is a very commonly used geometric representation of all possible right triangles with a hypotenuse length of one. If you have not yet encountered the unit circle in math class, the coordinates of each point on the circumference of the circle can be found simply by finding the sin and cosine of the angle created between the point and (0,0). The x value can be found as the cosine of the angle while the y value can be found as the sin of the angle. For this problem, you will be given the angle(from 0 to 359), and you should output the x value.
A single integer ranging from 0 to 359 that corresponds to the angle of the point on the unit circle.
A single floating point value that represents the x value of the point created on the unit circle by the given angle.
30
0.8660254037844387
Though digital communications are highly accurate, errors can occur from time to time. To deal with such communications errors, methods to detect and fix errors have been invented. One very common and simple method for this is known as a parity bit. When a message is being sent digitally in the form of bytes of 8 bits, a ninth parity bit can be added that is either 1 if the message has an even number of 1s(in binary), or 0 if the message has an odd number of 1s. While this method clearly will only work if there are an odd number of errors, it is a useful heuristic for detecting many errors without the need for more computation intensive methods. Your task for this problem is to write a program to determine if a nine bit sequence of binary is valid according to a parity check. The first bit on the left represents the parity bit, and the following 8 bits correspond to the one byte message that is to evaluated for parity.
Exactly 9 consecutive binary bits will be provided as input in the form of a one-line string with no spaces. The first bit on the left represents the even-parity bit, and the next eight bits represent the message being communicated.
Output either "NO ERROR" if the parity check is valid or "TRANSMISSION ERROR" if the parity check fails.
100110101
NO ERROR
Binary Coded Decimal(BCD) is a method of representing a value with binary notation while using the same digit places as base 10(decimal). For example, the value 783 in decimal translates to 1100001111 in standard binary, though it would instead translate to 011110000011 in binary converted decimal. This BCD converted value is composed of three chunks of 4 bits each, where each 4-bit chunk corresponds to a different digit from 783. While BCD is not used as commonly in software development, it is critical in 7-segment display systems. These circuits display a multi-digit number by splitting it into its individual digits, then sending each individual digit to a different display, creating the image of an entire number with multiple digits. Your task for this problem will be to take a base-ten decimal and to convert it into a BCD value. Each base-10 digit should be represented by four binary digits, and the individual chunks should be concatenated together to produce the final output.
A single integer value that represents the value to be converted to BCD.
A single binary value that represents the inputted value after being converted to BCD.
7193
0111000110010011
For this task, you will be required to find a set of simple statistics based on a given set of data. Data will be provided as an array of integers, and you will be tasked with finding the mean, median, mode, and range of the data.
The first line will contain $$$n$$$, the number of values in the array. The second line will contain space-separated integers that correspond to the array of input values.
The output should print the mean, median, mode, and range of the provided data in order and separated by lines(ie. the first line has the mean, the second line has the median, etc).
5 2 2 8 1 5
3.6 2.0 2 7
For this problem, you will be tasked with sorting a series of houses by how close they are to a given house. The rules for house distances are as follows: houses on the same street will have have a distance of the difference between their house numbers, and houses on different streets will experience a distance equal to the difference between their house numbers times the difference between their street numbers. Houses will be each provided with a unique name, such as "h1", and will also have a street number that represents which street they live on as well as a house number that represents their position on the street. For this problem, you will be given a series of houses and their respective values and you will need to determine which house is the closest to a specified house. For example, you may be given h1,h2,h3,h4,h5, then asked to find the closest house to h3.
The first line of input contains a single integer $$$n$$$ that represents the number of houses that are contained in the set. The next $$$n$$$ lines each contain information about a different house in the format: "name streetnum housenum". After $$$n$$$ lines, there will be one line that lists the name of the house that should be used in the nearest house computation.
A single string that represents the house that is closest to the given house name.
5 h1 1 100 h2 1 2 h3 2 15 h4 5 3 h5 3 7 h5
h3
While the equation of sin is highly stressed in high school math class, the methods for computing the sin of any input algebraically is usually not explained. There are various methods that can be used by computers or by hand, though the Taylor Approximation and CORDIC methods are most common. Calculators use CORDIC for its high speed and accuracy, though this problem will cover the Taylor Approximation method. If you have not yet had experience with calculus or the Taylor series, a Taylor Approximation is essentially a way to represent a function as a series of polynomial expressions. The use or details of this concept is not relevant to the question, though it is important to not that a Taylor Series will approximation its original function. In the case of the sin operation, the Taylor Approximation can be found as $$$x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!}...$$$ The pattern can be repeated continuously to increase the accuracy of the approximation, and the approximation will only work on smaller radian values of input. In addition, if you have not seen the $$$!$$$ operator before, it is known as the factorial. The factorial of a number can be computed as the number multiplied by each integer below it, so $$$3! = 3*2*1 = 6$$$. For this problem, you will be provided with number of terms to use for the Taylor Approximation along with a radian angle value for input into the equation. You should then output the approximation for sin of this input value using the given number of terms of the Taylor Approximation.
The first line will contain a single integer that represents the number of terms of the Taylor Approximation to use. The second line will have a single radian value that is to be input into the equation.
A single floating point value that represents the approximation of sin with the given number of equation terms and the given input value.
5 1
0.8414710097001764
For this problem, you will be tasked with finding the dot product of two given matrices. Dot products are a very common matrix operation, and find uses in many fields of math, computer science, and physics. If you haven't had any experience with a matrix in the past, think of matrices as a "table" of values, similar to a multi-dimensional array. Matrices can be of any dimension, yet this problem will only focus on two dimensional matrices. The result of a dot product operation on two matrices m1 and m2 in the form m1*m2 will result in a matrix with the same number of rows as m1, and the same number of columns as m2. It is difficult to explain the computation of the dot product in text, so here is an image representing it:
The first line contains four space separated integers, representing the width of m1, the height of m1, the width of m2, and the height of m2 respectively. The next lines will contain each row of m1 followed by each row of m2. Each row will include space separated integers that correspond to the values in that row of the matrix.
A single matrix that represents the result of computing the dot product of m1 and m2.
2 2 2 2 1 2 3 4 5 6 7 8
19 22 43 50
Pascal's Triangle is a famous concept in mathematics, and it has proven to have incredible relevance in many fields of mathematics even hundreds of years after its creation. The triangle is very simple to construct, starting out with just the number one centered on the first line of a sheet of paper. On the second line, write two ones centered just to the left and right of the one above. For any given line on the triangle, a value is found by adding the value to the upper right and upper left of the specified point, even if the upper right or upper left doesn't exist(meaning the specified point is on the edge of the triangle). Values on the edge of the triangle will always be 1. Your task for this problem is to find the maximum value on a given line of pascal's triangle(with the top line being 0).
A single integer that represents the line of pascal's triangle(with the top line being 0) to have the maximum found for.
A single integer that represents the maximum value on the given line of Pascal's Triangle.
5
10
If you are struggling with figuring this task out, take a look at binomial coefficients.
Ken Ken is a number puzzle created in 2004 by Tetsuya Miyamoto.
You're solving Ken Ken puzzles from a puzzle book. Each puzzle is an $$$n$$$ by $$$n$$$ grid, and you have to fill in all of the spaces in the grid.
There are also $$$k$$$ "freebie" spaces, which have already been filled in.
Given $$$n$$$, the size of the grid, figure out how many total spaces you have to fill in. For example, to solve a 4 by 4 puzzle with two freebies, you would have to fill in 14 spaces.
The first line of input consists of a single positive integer $$$n$$$: the size of the puzzle, indicating that the puzzle is an $$$n$$$ by $$$n$$$ grid.
The second line of input consists of a single positive integer $$$k$$$: the number of freebie spaces in the grid that have already been filled in.
Output a single integer $$$k$$$: the number of spaces in the puzzle that you have to fill in.
4 2
14
6 3
33
If you like Ken Ken, you should look at the hardest problem in this contest, which asks you to write a program to solve a Ken Ken puzzle.
After the end of hair salon restrictions of quarantine, many clients come to get their hair cut. Naturally, after months of uncut hair, your client's hairdos can be quite long! Your clients all have a preference of how long their hair needs to be after it is cut, and you can measure how long their hair is once you start cutting their hair.
You must determine how much hair you have to cut in order to reach the specified length of hair the client requested.
The first line will contain an integer $$$n$$$ which denotes the amount of test cases that will follow. Each line succeeding this value will contain two space separated integers representing the length in hair (in inches), the first one being the length of hair your client has at the beginning of the haircut, and the second being the length of hair your client wishes to have at the end of the haircut.
For each test case, print the amount of hair you must cut in order to fit the client's requirements.
3 14 8 12 5 25 15
6 7 10
Your younger sibling needs help with their algebra homework, and it involves a full worksheet of detecting parallel lines in equations! Too inarticulate to explain how to find these parallel lines, you decide to create a piece of code that will solve the problems for them.
You will be given two lines of linear equations in $$$y=mx+b$$$ form. See the example input for the exact formatting. $$$m$$$ will always be written before the $$$x$$$ term, even if $$$m$$$ is equal to 1.
If the two linear equations are parallel, output "PARALLEL", otherwise output "NOT PARALLEL".
y=17x+12 y=2x+21
NOT PARALLEL
y=-8x+3 y=-8x+1
PARALLEL
A "FizzBuzz" question is a standard interview question given to any computer science job applicants that tests the applicant's aptitude to solve and code basic problems, including the style they program in. A shocking fact, but many entry level computer science graduates do not know how to practically code, and this question is able to filter out the applicants that do not have the ability to program out of a simple question.
Given two numbers, $$$x$$$ and $$$y$$$, print out the numbers in between these two numbers, $$$x$$$ (inclusive) and $$$y$$$ (exclusive), but if the number is a multiple of 3, replace the printed number with the string, "Fizz", and if the number is a multiple of 5, replace the printed number with the string, "Buzz". If the number is a multiple of both 3 and 5, replace the printed number with the combination of the two strings, "FizzBuzz".
Given two line-separated integers $$$a$$$ and $$$b$$$, implement the method described above.
1 16
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
11 18
11 Fizz 13 14 FizzBuzz 16 17
You are working as a cashier for a supermarket, and items are handed to you to be scanned one by one by the customer. You do not know how many items they have, but after the last item is scanned, the customers usually say, "done".
A series of row separated floats representing prices, with the word "done" succeeding the last item of the customer's cart.
Print out the total price of all the items.
4.99 9.99 5.49 19.49 done
39.959999999999994
6.39 38.13 1996.39 105.30 55.99 done
2202.2
While doing your gym assignments in quarantine, your gym teacher makes you record your heart rate after your workouts, and separates them into five "zones". These zones of fitness are sorted dependant on your maximum heart rate (MHR), which is determined by taking your age, and subtracting it from 220.
The zones are separated thusly:
Zone 5: 90 - 100 percent of MHR
Zone 4: 80 - 89 percent of MHR
Zone 3 : 70 - 79 percent of MHR
Zone 2 : 60 - 69 percent of MHR
Zone 1 : <60 percent of MHR
Given the first line as the age of the student, the second line will contain an integer $$$n$$$ which denotes the amount of test cases to follow.
Print the appropriate fitness zone for each given test case.
16 3 165 152 86
Zone 4 Zone 3 Zone 1
25 5 103 166 182 153 123
Zone 1 Zone 4 Zone 5 Zone 3 Zone 2
Over the quarantine season, you decide to watch your weight by limiting yourself to a certain amount of calories a day. In your house, you stocked up on a small variety of foods before the quarantine, and regardless of what time of the day it is, you must choose from these items:
Steak: 500 Cal
Apple: 100 Cal
Bread: 50 Cal
You will be given a number $$$n$$$, denoting the number of calories you have limited yourself to for the day.
$$$n$$$ will be divisible by 50.
Print the minimum amount of articles of food you must consume for the day in order to reach your caloric limit exactly.
2350
Steak: 4 Apples: 3 Bread: 1
2500
Steak: 5 Apples: 0 Bread: 0
In the card game of blackjack, a player competes with a dealer, who in the first rounds, distributes two cards to both the player, and to themselves. These two cards determine the play of the next turn, as the objective of the game is to achieve a total score of 21, through the combination of number and face cards.
Each face card is worth 10 points, while the number cards are worth their value points in their numbers. An ace, however, is worth 11 points, but if an ace causes the player's pool to go over its 21 point limit, it may become devalued to 1 point.
You will be given two space-separated card values, the total of which will not be less than 10. Assume that given aces will automatically be valued at 11.
Print out the card value that you must get for the next round in order to reach a score of 21. If 10 points are needed, print "FACE CARD/10". If the two given cards' total value is already equal to 21, print, "BLACKJACK".
A 10
BLACKJACK
3 8
FACE CARD/10
6 4
A
6 7
8
First envisioned by the French mathematician, Blaise Pascal, Pascal's Triangle is a formation of numerals that are arranged in such a way that a number composing a part of the triangle is the summation of the adjacent binomial pair of the previous row in the triangle.
The only line of input contains a single positive integer $$$n$$$.
Output $$$n$$$ lines. The $$$i$$$th line should contain $$$i$$$ space-separated integers, consisting of the $$$i$$$th row of Pascal's Triangle.
5
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Morse code, developed in 1837, along with the invention of the telegram, was a revolutionary invention that struck a new frontier in the subject of telecommunications. Through a series of electrical pulses, messages could be sent to far distances through a series of dots and dashes, and at a speed that was unheard of before its invention. Since then, telegrams and Morse code have been essential in the realm of communications, especially in its role in the military, where fighter pilots were required to memorize Morse code until the 1990s.
Your job is to create a translator that will take in messages encode it in morse, and output the result in alphabet form.
You will receive a message, encoded in morse, whose dashes are represented by -, and dots represented by . Assume all letters will be uppercase. Each word will be separated via /, and each character will be separated by a space.
Print out the complete translated statement.
- .. - .- -. .. -.-. / - --- / .- -. -.-- / ... .... .. .--. / -.-. --.- -.. / -.-. --.- -.. / ... --- ... / .-. . --.- ..- .. .-. . / .. -- -- . -.. .. .- - . / .- ... ... .. ... - .- -. -.-. . / -.-. --- -- . / .- - / --- -. -.-. . / .-- . / ... - .-. ..- -.-. -.- / .- -. / .. -.-. . -... ..- .-. --.
TITANIC TO ANY SHIP CQD CQD SOS REQUIRE IMMEDIATE ASSISTANCE COME AT ONCE WE STRUCK AN ICEBURG
Every morning after you get out of bed, you brew yourself a nice cup of coffee to get yourself ready for the day. However, most of the time when you pick up the coffee to drink, it's too hot for you to drink! You know that Newton's Formula of Cooling is $$$T(t) = T_{s} + (T_{0} - T_{s})e^{-kt}$$$, where:
$$$T(t)$$$ is the temperature of the coffee at time $$$t$$$,
$$$T_{s}$$$ is the ambient temperature of the room,
$$$T_{0}$$$ is the initial temperature of the coffee, and
$$$k$$$ is the decay constant.
You also know that the coffee reaches your favorable heat from a initial temperature of 210 degrees to 120 degrees after 15 minutes of cooling, in a room temperature of 70 degrees.
The first line of input will be an integer $$$n$$$, which denotes the amount of test cases to follow in the subsequent lines. The test cases will contain a positive integer $$$T(t)$$$, the temperature at time $$$t$$$.
For each test case, output the time $$$t$$$ minutes it takes for the freshly brewed coffee to cool town to temperature $$$T(t)$$$.
3 150 120 90
8.152756910910513 15.000000000000002 28.348972201535375
A number is called a palindrome if it reads the same forwards and backwards. For example, 5775, 98389, 7, and 66 are palindromes, but 552, 35, and 86867 are not palindromes.
Given a number $$$n$$$, figure out the closest $$$k$$$ palindromes to $$$n$$$. If two palindromes have the same distance away from $$$n$$$, print the smaller one first.
For example, let's say $$$n$$$ = 600 and $$$k$$$ = 4.
The closest palindrome to $$$n$$$ is 595, with a distance of 5. The next closest palindrome is 606, with a distance of 6. The next two are 585 (distance of 15) and 616 (distance of 16), so we would print 595, 606, 585, and 616, in that order.
The only line of input consists of two space-separated integers $$$n$$$ and $$$k$$$: the number to check palindromes near, and the number of palindromes to print out, respectively.
Output $$$k$$$ lines, each consisting of a palindrome, sorted by their distance from $$$n$$$ (calculated as abs($$$n$$$ - $$$p$$$) for a palindrome $$$p$$$).
The palindromes must be positive integers.
600 4
595 606 585 616
753 8
757 747 767 737 777 727 787 717
6 10
6 5 7 4 8 3 9 2 1 11
You're tired of the warm July weather, so you and your friends decide to take a trip to Antarctica, and have a snowball fight.
Each person is given a very large number of snowballs (essentially, an infinite number). Each person is also wearing a coat with a certain color, and boots with a certain color.
Throughout the snowball fight, each person throws their snowballs at everyone else who doesn't either have the same color of coat, or the same color of boots, exactly once. Obviously, people don't throw snowballs at themselves.
Given this information, figure out how many snowballs are thrown in total during the snowball fight.
The first line of input consists of a single positive integer $$$n$$$: the number of people involved in the snowball fight.
The next line of input consists of $$$n$$$ space-separated strings: the coat color of each person involved in the snowball fight, in order.
The next line of input consists of $$$n$$$ space-separated strings: the boot color of each person involved in the snowball fight, in order.
Output a single positive integer $$$n$$$: the total number of snowballs that are thrown during the snowball fight.
5 red red green green blue red blue yellow green green
14
5 red red green yellow purple brown blue maroon pink orange
18
There have been a lot of online Codeforces contests recently.
On Codeforces, each user is given a rating, which is a positive integer less than 4000. After each worldwide contest (which 10000+ users compete in on average), everyone's rating value increases or decreases, depending on their performance in the competition. The higher your rating, the higher rank you will need to get a positive rating change. For example, if a user had a rating of 3700, their rating could decrease if they got 2nd place in a contest (out of 10000+ people). On the other hand, if a user was rated 900, their rating would increase even if they came in 5000th or 6000th place (out of 10000). As a result of this formula, the list of the top 10 users on Codeforces (based on rating) is constantly changing, although one person is usually at #1.
You're given a list of $$$n$$$ codeforces users, and their rating before any of the recent contests. You're then given a list of $$$k$$$ contests. Each contests contains the rating change for each contestant. Given this information, your task is to print out the list of the top 10 highest rated users after each contest.
The first line of input consists of two space-separated integers $$$n$$$ and $$$k$$$: the number of Codeforces users, and the number of contests, respectively.
The second line of input consists of $$$n$$$ space-separated strings: each Codeforces user's username
The third line of input consists of $$$n$$$ space-separated positive integers: each Codeforces user's rating, before any of the recent contests
The next $$$k$$$ lines each contain info about a single contest. Each line will contain $$$n$$$ space-separated integers: the rating change for each user. Each user's index in the contest rating change list will be the same as their index in the original list of users. For example, if someone appeared first in the original list of users, their rating change would be first in each list of contest rating changes.
Each rating change will be given as +[amount], if the rating change was positive, -[amount], if the rating change was negative, and 0 otherwise. For example, +345, -172, and 0 are all valid rating changes.
Output $$$k$$$ lines. On each line, output the names of the top 10 highest rated users after each contest. If two users have the same rating, sort them alphabetically by their username from lowest to highest.
12 6 MiFaFaOvO tourist Um_nik ecnerwala maroonrk 300iq Petr LHiC Benq TLE apiadu Radewoosh 3681 3669 3358 3119 3232 3317 3016 3229 3230 3374 3397 3104 0 +4 +135 +97 +18 0 +141 0 0 -151 0 -168 0 +60 0 +57 -7 0 +30 0 -17 0 0 +171 0 -192 -59 -13 +110 0 0 0 +7 0 0 -2 0 -132 +110 0 +78 0 0 0 +40 0 0 -115 0 +111 +23 +49 -10 0 0 0 +23 0 0 +65 0 +47 -40 +149 -12 0 +85 0 -57 0 -214 +102
MiFaFaOvO tourist Um_nik apiadu 300iq maroonrk Benq LHiC TLE ecnerwala tourist MiFaFaOvO Um_nik apiadu 300iq ecnerwala maroonrk LHiC TLE Benq MiFaFaOvO tourist Um_nik apiadu maroonrk 300iq ecnerwala LHiC TLE Benq MiFaFaOvO Um_nik maroonrk tourist apiadu 300iq Benq ecnerwala LHiC TLE MiFaFaOvO Um_nik tourist maroonrk apiadu 300iq ecnerwala Benq LHiC TLE MiFaFaOvO tourist Um_nik ecnerwala maroonrk 300iq Petr LHiC Benq TLE
12 6 MiFaFaOvO tourist Um_nik ecnerwala maroonrk 300iq Petr LHiC Benq TLE apiadu Radewoosh 3681 3669 3358 3119 3232 3317 3016 3229 3230 3374 3397 3104 0 +12 +135 +97 +18 0 +141 0 0 -151 0 -168 0 +60 0 +57 -7 0 +30 0 -17 0 0 +171 0 -192 -59 -13 +110 0 0 0 +7 0 0 -2 0 -132 +110 0 +78 0 0 0 +40 0 0 -115 0 +111 +23 +49 -10 0 0 0 +23 0 0 +65 0 +47 -40 +149 -12 0 +85 0 -57 0 -214 +102
MiFaFaOvO tourist Um_nik apiadu 300iq maroonrk Benq LHiC TLE ecnerwala tourist MiFaFaOvO Um_nik apiadu 300iq ecnerwala maroonrk LHiC TLE Benq MiFaFaOvO tourist Um_nik apiadu maroonrk 300iq ecnerwala LHiC TLE Benq MiFaFaOvO Um_nik maroonrk tourist apiadu 300iq Benq ecnerwala LHiC TLE MiFaFaOvO Um_nik tourist maroonrk apiadu 300iq ecnerwala Benq LHiC TLE MiFaFaOvO tourist Um_nik ecnerwala maroonrk 300iq Petr LHiC Benq TLE
You're traveling through space, but unfortunately, your spaceship has a limited amount of fuel. There are $$$n$$$ planets that you want to travel to on your journey through space, and each planet can be represented by an $$$x$$$, $$$y$$$, and $$$z$$$ coordinate.
You start on Earth, which can be represented as the origin (0, 0, 0) on the 3D coordinate plane. You want to find the minimum distance you can travel, if you start on Earth, visit all of the planets at least once, and end on Earth.
Recall that to calculate the distance between two points in 3D space, you can use the distance formula:
The first line of input consists of a single positive integer $$$n$$$: the number of planets. $$$n$$$ will be less than or equal to 8.
The next $$$n$$$ lines each contain three space-separated integers: the $$$x$$$, $$$y$$$, and $$$z$$$ coordinates of each planet.
Remember that the coordinates of the Earth are (0, 0, 0).
Output a single positive integer: the minimum total distance that you travel, if you start and end on Earth, and visit all of the planets.
Don't round your answer.
4 -1 0 0 -2 0 0 2 0 0 1 0 0
8.0
8 3 3 2 -3 -3 8 6 8 7 -5 6 3 -2 7 6 -4 4 -3 1 5 -3 5 4 0
59.308719980502595
4 3 3 -2 -2 5 4 4 8 -6 8 17 -3
45.292233300341344
Over the quarantine season, you decide to watch your weight by limiting yourself to a certain amount of calories a day.
In this problem, you're given the number of calories of each food item in your house as input.
You want to figure out the minimum number of food items that you need to eat in order to have eaten exactly $$$n$$$ calories.
The first line of input contains a single positive integer $$$n$$$: the target number of calories.
The second line of input contains a single positive integer $$$k$$$: the number of food items.
The next $$$k$$$ lines each contain a single positive integer $$$c$$$: the number of calories of each food item.
Output a single positive integer $$$m$$$: the minimum number of food items that you need to eat, in order to have eaten exactly $$$n$$$ calories.
2310 3 500 100 10
8
600 3 500 300 1
2
10000 3 3 7 11
912
This problem is not as easy as you think it is. The solution to the easier version of the problem does not correctly solve the second example case.
You're testing out a catapult that you built for POE class, and you're trying to get it to launch an eraser over a wall.
The catapult launches the eraser $$$a$$$ meters away from the wall, and you're trying to get the catapult to hit a target $$$b$$$ feet above the ground, and $$$c$$$ meters away from the wall in the exact opposite direction.
The wall is $$$d$$$ meters high, and it is very thin (assume it has no thickness).
Given this information, figure out the minimum possible maximum height of the eraser, such that the eraser still clears the wall. In other words, among all eraser trajectories that hit the target and successfully clear the wall, find the lowest possible maximum height of the eraser.
Assume that you launch the device in a vacuum (i.e. there is no air resistance).
The only line of input contains 4 space-separated positive integers: $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$, as described above. $$$b$$$ is guaranteed to be less than $$$d$$$.
Output a single positive integer $$$h$$$: the maximum height of the eraser, if you launch it so that it hits the target and clears the wall, and has the minimum possible maximum height.
5 0 5 7
7.0000000000000195
5 0 9 7
7.62222191701435
5 6 1 12
15.778572363190715
You don't need to use any physics equations to solve this problem. You can solve it using only algebra.
Also, your answers don't have to be exactly equal to ours. As long as they're within a few decimal places, your solution will be judged as correct.
Ken Ken is a number puzzle created in 2004 by Tetsuya Miyamoto.
Like Sudoku, Ken Ken involves placing numbers into an n by n grid, and it requires each row and column to contain distinct integers from 1 to n. n can range from 4 to 7, inclusive.
Additionally, each of the n * n cells in the Ken Ken puzzle is assigned to a "cage" consisting of one or more cells. If a cage consists of multiple cells, they have to form a single block of cells connected vertically or horizontally, but not diagonally. For example, an L-shaped cage, or a 2 by 2 square cage would be valid, but a cage consisting only of two cells at the opposite end of the board would not be valid. Usually, cages don't have more than 4-5 cells (although there is no upper limit).
For each cage in the puzzle, if it consists of only one cell, the cage will simply be assigned a number, indicating which number is placed in the cage in the final solution. This is called a "freebie".
Otherwise, each cage with two or more cells is assigned a math operation. All of the cells in the cages must complete the math operation successfully. For example, if a cage had the operation "9+", the total sum of the numbers in the cells of the cage would have to sum to 9. If a cage had the operation "120x", the total product of the numbers in the cage would have to be 120.
Cages can also have subtraction or division operations. These types of cages have to have exactly two cells. For subtraction, the difference of the two numbers in the cage must equal the given number. For example, if a cage had the operation "2-", then the numbers could be 3 and 1, in any order. They could also be 4 and 2, 2 and 4, 5 and 3 (if the board was at least 5 by 5), and so on. Cages with division work similarly. The number in the cage must equal the quotient of the higher number divided by the lower number. For example, for a "2/" cage, the numbers could be 1 and 2, or 2 and 1, or 4 and 2, and so on. As such, the required number of a cage will always be a positive integer.
Note that although all rows and columns must consist of distinct numbers, cages do not have to.
Here's an example of what an unsolved Ken Ken puzzle looks like:
And here's the solution to the same Ken Ken puzzle:
Your task, as you might have guessed, is to write a program to solve a Ken Ken puzzle. All of the Ken Ken puzzles will range from 4 by 4 to 7 by 7 in size, and they will all be taken from a book of Ken Ken puzzles, meaning that they will all be potentially solvable by a human.
Good luck!
The first line of input consists of a single positive integer $$$n$$$: representing the size of the Ken Ken puzzle (the puzzle will be an $$$n$$$ by $$$n$$$ puzzle). $$$n$$$ will be less than or equal to 7 for this problem.
The next lines will contain a grid representation of the Ken Ken puzzle. Each cage will be marked off with pipes ("|") and hyphens ("-"). See the example cases for the exact formatting of the input.
The cell in each cage closest to the top of the puzzle will contain the math operation. If two cells in a cage are the same distance from the top of the puzzle, the leftmost one will contain the math operation.
Output $$$n$$$ lines, each consisting of $$$n$$$ integers: the solution to the Ken Ken puzzle.
5 |---|---|---|---|---| |40x |2- | | | | |---|---|---|---|---| |8+ |24x |8+ | | | | | | |---|---|---| | | |8+ | | | | | | |---|---| |---|---| |5+ | |15x | | | | | |---|---| |---|---| |2- | |2/ | | | | | |---|---|---|---|---|
25431 12345 34512 41253 53124
5 |---|---|---|---|---| |2- |12+|2 |10x|2/ | | | | | | | | | |---| | | | | |12x| | | | | | | | | |---| | | |---| |3- | | | |20x| | | | | | | | |---| |---| | | |20+| | | | | | | | | | |---| |---| |---| | | | | |-------------------|
34251 53412 15324 42135 21543
Welcome to the CodeRams team competition!
If you're not sure on the competition format or how to submit solutions, read this first.
Since your team may not have time to get through all of the problems, we recommend that you read all problems (since harder problems give more points).
Good luck! Here's the first problem:
Given a positive number, figure out whether or not it is a multiple of two. For example, 6 is a multiple of two, while 11 is not a multiple of two.
The only line of input contains a positive integer.
Print YES if the integer is a multiple of 2, and NO otherwise.
3
NO
10
YES
For an engineering challenge, you have to make a project which has a certain height $$$n$$$, with a tolerance of $$$k$$$. This means that any height between $$$n$$$ - $$$k$$$ and $$$n$$$ + $$$k$$$ will be acceptable. For example, if $$$n$$$ was equal to 5, and $$$k$$$ was equal to 2, any height between 3 and 7, inclusive, would be acceptable.
Given these values $$$n$$$ and $$$k$$$, figure out the lower and upper height limit for the engineering project.
The input consists of two lines: positive integers $$$n$$$ and $$$k$$$, each on separate lines.
Output two lines. On the first line, output the lower height limit, as described above. On the second line, output the upper height limit, as described above.
5 2
3 7
7 3
4 10
8 4
4 12
You consider a string of text to be boring if it contains only "a" characters and "b" characters. For example, "abbaba" is boring, while "abcccbabc" is not boring.
Given a string, figure out whether or not it is a boring string.
The only line of input contains a single string $$$s$$$, not containing spaces.
If $$$s$$$ is boring, as described above, output "YES" (no quotes). Otherwise, output "NO".
aaaaaa
YES
ccabbabbdd
NO
baaaaabad
NO
baaaaabba
YES
You like sequences of numbers that are in sorted order. You have three integers, and you want to figure out whether or not they're sorted, i.e. the first number is less than (not equal to) the second number, and the second number is less than (not equal to) the third number.
The only line of input consists of three space-separated integers.
If the three integers given are sorted, output "SORTED" (no quotes). Otherwise, output "UNSORTED".
3 5 8
SORTED
6 6 7
UNSORTED
5 2 1
UNSORTED
You consider a number to be "lucky" if it has any digits equal to 7. For example, 7377, 87, and 98789 are lucky, while 6, 300, and 561 are not lucky. Given a number, figure out whether or not it is a lucky number.
The only line of input consists of a single integer $$$n$$$.
If $$$n$$$ is a lucky number, output "YES" (no quotes). Otherwise, output "NO" (no quotes).
7377
YES
1101
NO
3060
NO
After destroying half of all life in the universe, Thanos decides to destroy one-third of all positive integers in the universe. Thanos starts by destroying 0, and then proceeds to destroy any positive integers that are a multiple of 3.
Your task is to find the first $$$n$$$ integers that are left (have not been destroyed) after Thanos applies this operation. For example, the first 5 integers that are left are 1, 2, 4, 5, and 7.
The only line of input consists of a single positive integer $$$n$$$: the number of integers to print.
Output $$$n$$$ lines: the first $$$n$$$ integers that were not destroyed by Thanos.
5
1 2 4 5 7
11
1 2 4 5 7 8 10 11 13 14 16
3
1 2 4
You have $$$n$$$ positive integers, and you want to find their product. However, you have to omit exactly one of the integers from the list before calculating the product. You want to find the maximum product of the list, after omitting exactly one integer from the list.
For example, given the numbers $$$2$$$, $$$4$$$, and $$$5$$$, the maximum product is $$$5$$$ * $$$4$$$ = $$$20$$$. $$$2$$$ * $$$4$$$ * $$$5$$$ is not valid, because none of the numbers were omitted.
The first line of input contains a single positive integer $$$n$$$: the number of integers in the list.
The next $$$n$$$ lines each contain a single positive integer: each element of the list.
Output a single positive integer $$$p$$$: the maximum possible product of all integers in the list, if you omit exactly one. The answer is guaranteed to fit inside of a 32-bit integer type.
5 3 5 6 8 10
2400
4 4 3 2 1
24
5 3 3 3 3 3
81
You consider a number to be a pleasing number if it contains no prime factors other than 2 and 3. For example, 1, 4, 12, 18, and 81 are pleasing numbers, while 7, 28, 210, and 30 are not pleasing numbers.
Given a number, figure out whether or not it is a pleasing number.
The only line of input consists of a single positive integer $$$n$$$ less than or equal to 1000.
If $$$n$$$ is a pleasing number, as described above, output "YES" (no quotes). Otherwise, output "NO" (no quotes).
18
YES
35
NO
You're listening to the radio, and you have a "voice to text" machine that transcribes the radio's words. The machine transcribes some of the static of the radio, however, which it writes as certain random characters. The machine writes an underscore character before and after any static that it transcribes. Your task is to filter out the static and print the original message.
For example, if the machine transcribed "hello wor_xxxxxxxhsfdjsdkkdsfds_ld coderams", the filtered out text would be "hello world coderams".
The only line of input contains a line of text, following the rules above.
Output a single line: the text, after filtering out the static, as described above.
hellowor_*%^&&^%&^&%*_ldcoder_%^%^_ams
helloworldcoderams
hello_***_hello
hellohello
_^*&^^&**&^*^&*&^*^&_code ram_^_s^^^
code rams^^^
You just went on a very hilly bike ride, and you want to find largest hill that you biked up during your ride.
You know the elevations of several points along your ride, and you want to find the vertical rise of the largest continously uphill section of the ride. A continuously uphill section must have a positive overall vertical rise, and must consist of only uphill segments. If a section of the ride has any downhill or flat subsections, it is not considered a continuously uphill section.
The first line of input contains a single positive integer $$$n$$$: the number of points along the ride that you know the elevations for.
The next line contains $$$n$$$ space-separated integers: the elevation, along each point of the ride.
Output a single positive integer $$$v$$$: the value of the biggest hill on the ride, defined as the vertical rise of the largest continiously uphill section, as defined above. There is guaranteed to be at least one continously uphill section in the route given in the input.
7 600 650 700 690 740 520 600
100
5 400 500 600 700 400
300
8 100 200 300 300 400 500 600 700
400
You have two numbers, and you decide to apply a special addition technique on them: you convert both numbers to quaternary (base 4), and add each digit pair separately. If this results in a number greater than or equal to 4, you subtract four from the result.
For example, if you had the numbers 322312 and 213200 in base 4, the result would be 131112.
Given two numbers in base ten, apply this technique on them, and convert the result back into base 10.
The first line of input contains a single positive integer $$$a$$$.
The second line of input contains a single positive integer $$$b$$$.
Print the result of applying the operation described above on $$$a$$$ and $$$b$$$, converted back into decimal (Base 10).
7 9
12
67 130
193
45 1003
964
You're on an intergalactic space mission in the year 2100, and you come across a star with several planets orbiting it. You know the coordinates of each planet in 3D space, and given this information, you need to find the ordering of the planets from closest to farthest away from the star. Then, you can figure out which planets are most likely to have alien life forms.
You're given the coordinates of the star of the planetary system, and the coordinates for $$$n$$$ planets orbiting the star, and their names.
Recall that you can use the 3D distance formula to calculate the distance between two planets in 3D space:
The first line of input consists of three space-separated integers: the X, Y, and Z coordinates of the star, respectively.
The next line of input contains a single positive integer $$$n$$$: the number of planets orbiting the star.
The next $$$n$$$ lines each contain three space-separated integers, representing the X, Y, and Z coordinates of each planet, respectively, followed by a space and a single string, representing the name of the planet.
No two planets in the input file will have the same distance away from the star.
Output $$$n$$$ lines: the names of each planet in the exoplanetary system, ordered based on their distance from the star. The planet closest to the star should come first in the list, and the planet the furthest away from the star should come last in the list.
20 20 20 8 16 19 20 Venus 10 20 20 Mars 14 22 20 Earth 18 20 20 Mercury -5 17 20 Uranus 2 21 21 Saturn 6 20 23 Jupiter -11 20 21 Neptune
Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune
During the coronavirus pandemic, your town is attempting to trace the origins of recent COVID-19 cases.
You're given a list of people who had the disease, and who they got it from, and you're trying to find the names of "superspreaders". For this problem, we'll define a superspreader as someone who gave at least three other people COVID-19.
Given this information, your task is to figure out the names of all of the superspreaders in the town.
The first line of input contains a single positive integer $$$n$$$: the number of people in the town.
The next $$$n$$$ lines contain two space-separated strings: the name of each person, and the name of the person they got the coronavirus from. Exactly one person in the town will have "OTHER" (no quotes) as the person they got the disease from, indicating that this person got the disease from a different town.
Output $$$k$$$ lines, where $$$k$$$ is the number of superspreaders in the town. On each line, print the name of each superspreader in the order they were given in the input.
If there aren't any superspreaders in the town, output "NONE" (no quotes).
10 Alice OTHER Bob Alice Cheryl Alice Darryl Bob Ernie Alice Frank Darryl Greta Darryl Hank Cheryl Irene Bob John Darryl
Alice Darryl
4 Keith OTHER Larry Keith Marshall Larry Nancy Marshall
NONE
6 Alice Frank Bob Ernie Cheryl Darryl Darryl Ernie Ernie OTHER Frank Ernie
Ernie
You're trying to encrypt text using the Morbit Cipher, a cipher involving morse code.
Encrypting text using the Morbit Cipher involves several steps:
1. Convert the text to Morse Code. This involves converting all letters to their Morse Code equivalents, and placing a lowercase x letter in between two letters, and two lowercase x letters in between two words. See below for a list of morse code mappings which you can copy into your program.
2. Divide the Morse Code into blocks of two characters each. If there are an odd number of characters, add an "x" to the end of the Morse Code. There are now 9 total combinations of two-character blocks, since each position can have three possible characters (dot, dash, and "x").
3. Write each of the 9 combinations of two-character blocks in an arbitrary order, assigning each one to an integer from 1 to 9. This is the "key" of the cipher.
4. Replace each two-character block in the Morse Code text of the cipher with the number it corresponds to in the key.
5. You should now have a long sequence of numbers from 1-9. Now, your text is encrypted using the Morbit Cipher.
Here is a comma-separated list of the Morse Code equivalents of each letter from A to Z, in order. You can copy this into your program:
".-", "-...", "-.-.", "-..", ".", "..-.", "–.", "....", "..", ".—", "-.-", ".-..", "–", "-.", —", ".–.", "–.-", ".-.", "...", "-", "..-", "...-", ".–", "-..-", "-.–", "–.."
The first line of input contains a line of text, consisting of only lowercase characters and spaces: the plaintext to encrypt using the Morbit Cipher.
The next 9 lines each contain a two-character block: the first one corresponds to the block that maps to "1", the second one corresponds to the block that maps to "2", and so on.
Output a single string of numbers from 1 to 9: the plaintext, after applying the Morbit Cipher on it using the given key.
we hope youre having fun in the competition so far xx .- -. x. .x .. -- -x x-
285465782341379742434166486245393163429545318664133979823494586979546971634825
good luck in the rest of it xx .- x- .x -. -x .. -- x.
8486865495476553217343974495997318675173
You have an 8 by 8 chessboard with several knights on it. The chessboard has no other pieces on it. Given the positions of the knights, find all of the spaces that the knights can travel to in a single move.
Recall that in chess, a knight can move exactly 2 spaces in one direction, and exactly one space in a perpendicular direction. For example, a knight could move 2 spaces left and 1 space up, or 2 spaces up and 1 space left, but a knight could not move 2 spaces left on its own, or 1 space up and 1 space right, for example.
The input consists of 8 lines, each consisting of 8 characters, representing the chessboard.
A single dot (".") represents an empty space on the chessboard, and an uppercase K ("K") represents the position of a knight.
Output 8 lines, in the same format as the input, except, replace each empty space that can be moved to by at least one knight in a single move with an asterisk ("*").
........ ........ ........ ...K.... ........ .....K.. ........ ........
........ ..*.*... .*...*.. ...K*.*. .*.*.*.* ..*.*K.. ...*...* ....*.*.
........ ..K....K ........ ...K.... ........ .....K.. ........ ......KK
*...**.. ..K.*..K **..**.. .*.K*.*. .*.*.*.* ..*.*K** ...***.* ....*.KK
........ ........ ........ ........ ........ ........ ........ .......K
........ ........ ........ ........ ........ ......*. .....*.. .......K
You're given a quadratic equation, in the form of $$$y = ax^2 + bx + c$$$. Your task is to find all possible factorizations of this quadratic equation, using only positive integers. In other words, you have to find all pairs of binomials $$$cx + d$$$, where $$$c$$$ and $$$c$$$ are both positive integers, such that the product of the two binomials is the original quadratic equation.
Sort the factorizations in ASCII order (you can use your language's built-in sorting method).
The only line of input contains three space-separated positive integers $$$a$$$, $$$b$$$, and $$$c$$$: the coefficient on the $$$x$$$ term of the quadratic equation, and the constant term of the quadratic equation, respectively.
Output all of the integer factorizations of the given quadratic equation, each on a new line. Each one should be in the format $$$(x + c1)(x + c2)$$$.
If there are no possible factorizations, output "-1" (no quotes).
2 8 6
(2x + 2)(x + 3) (2x + 6)(x + 1) (x + 1)(2x + 6) (x + 3)(2x + 2)
1 17 60
(x + 12)(x + 5) (x + 5)(x + 12)
3 7 11
-1
The RSA cipher, invented in 1977, is widely used today for encryption of data online. The first step of making a key for the RSA cipher is choosing a number $$$n$$$ at the start. In the real world, $$$n$$$ is extremely large, usually at least 50 digits long, but for this problem, you'll select an $$$n$$$ less than $$$10^6$$$.
When choosing the numbers for the key, $$$n$$$ must be a semiprime. A semiprime is any number that has exactly two prime factors, not necessarily distinct. For example, 6, 34, and 25 are semiprimes, but 30, 7, and 27 are not semiprimes.
After choosing $$$n$$$, you choose another number $$$e$$$, which can be any number less than $$$n$$$ and greater than one that is relatively prime to $$$n$$$. Two numbers are relatively prime if they don't share any prime factors.
$$$n$$$ and $$$e$$$ compose the "public key", and the private key is calculated differently, which won't be covered in this problem.
Given a number $$$m$$$, find the public key that has the largest $$$n$$$, where $$$n$$$ and $$$e$$$ are less than or equal to $$$m$$$. If multiple answers have the same $$$n$$$, pick the one with the smallest $$$e$$$.
The only line of input contains a single positive integer $$$m$$$: the upper limit on $$$n$$$ and $$$e$$$.
Output two space-separated integers, representing your chosen public key: $$$n$$$ and $$$e$$$, as described above. $$$n$$$ and $$$e$$$ should both be less than or equal $$$m$$$, $$$n$$$ should be a semiprime, and $$$e$$$ should be relatively prime to $$$n$$$.
197
194 3
259
259 2
372
371 2
98276
98267 2
Unfortunately, you find yourself trapped in a dungeon, which can be represented as a 2D grid. The dungeon contains some impassable walls, represented by X characters, and empty space, represented as single dots (".").
You start in the top left corner. You want to figure out how many cells are accessible from your starting space. You can move up, down, right, and left any number of times, but you cannot move diagonally, and you cannot move through walls. You also can't go off the board.
The first line of input consists of a single positive integer $$$n$$$: the number of rows and columns of the dungeon (the dungeon is always square).
The next $$$n$$$ lines each contain $$$n$$$ characters: the grid representation of the dungeon. If a character is an "X", it represents an impassable wall, and if a character is a single dot, it represents empty space.
Output a single positive integer $$$k$$$: the number of spaces in the dungeon accessible from your starting space, according to the rules above.
5 ...X. ..X.. ....X ..XXX .X...
15
5 ..X.. .XX.. X.... ..... .....
3
After the COVID-19 pandemic, a school decides to implement serious measures to ensure that students "socially distance" from each other. The school has divided each classroom into several squares, using glass walls, and each student is assigned to a single "sub-room" in the classroom.
Unfortunately, this strategy didn't accomodate enough students. To fix this, the school decided to stack several sub-rooms on top of each other, such that the sub-rooms form a cube. In other words, each classroom has $$$n^3$$$ sub-rooms, where $$$n$$$ is given as input.
Since everything was messed up by the COVID-19 quarantine, the school's classes all contain students of a wide range of ages. A student is called a leader if they're older than all of the students in adjacent sub-rooms, including diagonally (for example, a sub-room in the center of a classroom with $$$n=3$$$ would have 26 adjacent sub-rooms).
The teacher of the class wants to figure out which students are most likely to cause trouble. The teacher deduces that a student is likely to cause trouble if the following are true:
1. The student is not a leader (at least one student in an adjacent sub-room is older than them or the same age as them)
2. The student doesn't have any leaders in adjacent sub-rooms (including diagonally)
Given this information, help the teacher find out how many students in the classroom are likely to be troublemakers.
The first line of input contains a single positive integer $$$n$$$: the number of sub-rooms in a single 1D cross-section of the classroom. There are $$$n^3$$$ sub-rooms and students in total.
The next $$$n$$$ lines each contain a 2D grid of space-separated integers: the ages of the students in each top-down cross-section of the classroom. Each cross-section will be separated by a new line.
Output a single integer $$$k$$$: the number of potential troublemakers in the 3D classroom.
3 13 11 15 10 12 18 3 16 12 11 12 17 9 12 13 18 15 15 14 15 16 13 9 8 12 10 7
5
2 4 4 4 4 5 5 5 5
8
You're given three lines on the coordinate plane. No pairs of the lines are parallel.
Figure out the area of the triangle formed by the intersection points of the three lines. In other words, label the points of interesection of lines 1 and 2, lines 1 and 3, and lines 2 and 3, $$$A$$$, $$$B$$$, and $$$C$$$, respectively. Then, your task is to find the area of triangle $$$ABC$$$.
The input consists of three lines, each containing the equation for one of the lines, in $$$y = mx + b$$$ form, where $$$m$$$ represents the slope of the line, and $$$b$$$ represents the y-intercept of the line.
Output a single decimal number representing the area of the triangle formed by the intersection points of the three lines. Do not round your answer. Your answer doesn't have to be exactly equal to ours; as long as it's within a few decimal places it will be judged as correct.
y = 2x + 3 y = -2x + 9 y = x - 2
28.166666666666664
y = 2x + 3 y = -2x + 9 y = -x - 27
793.5000000000001
y = 2x + 3 y = -2x + 90 y = 7x - 2
478.4027777777778
Here is the graph of the first example case:
It is March, and the NCAA basketball tournament is happening soon. You're trying to figure out which teams have the best chances at winning the tournament.
Leading "bracketologists" have calculated, for each team, their probability of winning against each of the other teams. In other words, you know, for every pair of teams, the probability of each of the two teams winning in a game between the two teams, which can be represented by a table (more information in the input section).
There are $$$n$$$ teams in the tournament. $$$n$$$ will always be a power of two. Each team is given a unique number (their "seed"), from 1 to $$$n$$$.
In the first round of the tournament, the team with seed $$$s$$$ plays the team with the seed $$$n$$$ - $$$s$$$ + 1. For example, in the first round of an 8-team tournament, the 1 seed will play the 8 seed, the 2 seed will play the 7 seed, and the 3 seed will play the 6 seed.
After the first round, the teams that lost their match are eliminated from the tournament, and the teams that won their match move on to the next round.
In the next round, there are $$$\frac{n}{2}$$$ teams still left in the tournament. If every team with a lower numbered seed won each game, the second round proceeds similarly to the first round. For example, in the second round of an 8 player tournament where every lower numbered seed won each first round game, the 1 seed plays the 4 seed, and the 2 seed plays the 3 seed.
If a higher numbered seed won a first round game, they will play in the second round game that the team they beat would have played in. For example, if the 7 seed beat the 2 seed in the first round of an 8 player tournament, then the 7 seed would play the 3 seed in the second round, or the 6 seed, if the 6 seed beat the 3 seed in the first round.
This process repeats until the finals, when the winner of the finals wins the whole tournament.
Given the probability table described above, sort the teams by their probability to win the entire tournament.
The first line contains a single positive integer $$$n$$$: the number of teams in the tournament. $$$n$$$ is guaranteed to be a power of two.
The next line contains $$$n$$$ space-separated strings: the name of each team in the tournament.
The next $$$n$$$ lines each contain $$$n$$$ space-separated integers. The $$$j$$$th integer on the $$$i$$$th line represents the probability that the $$$i$$$th seeded team will beat the $$$j$$$th seeded team. The probabilities will be given as an integer percentage out of 100. The probability that a team will beat themselves will be given as 50
Output $$$n$$$ lines. Each line should contain the name of each team, a space, and the probability that the team will win the tournament, given as a percentage out of 100, rounded to the nearest integer. Sort the teams from highest to lowest, based on their probability of winning the tournament.
Note that you should round your answers after sorting the list of teams and their win probabilities.
4 Syracuse Michigan Duke UNC 50 78 47 52 22 50 21 19 53 79 50 60 48 81 40 50
Duke 45 Syracuse 28 UNC 23 Michigan 4
8 Syracuse Duke Louisville UNC Virginia Pittsburgh Indiana Kansas 50 54 62 51 55 97 83 35 46 50 52 43 57 94 65 29 38 48 50 34 48 87 81 31 49 57 66 50 54 96 77 23 45 43 52 46 50 90 55 11 3 6 13 4 10 50 33 1 17 35 19 23 45 67 50 15 65 81 69 77 89 99 85 50
Kansas 40 Louisville 18 Duke 14 Syracuse 11 UNC 11 Virginia 5 Indiana 2 Pittsburgh 0
Your team solved all of the problems at CodeQuest 2021, and as a reward, the supervisors of the competition decided to show your team a room full of new aircraft (CodeQuest is run by Lockheed Martin, which builds airplanes and helicopters at their Owego, NY site, which the CodeRams attend every year).
Once your team is dropped off in a room, the CodeQuest supervisors will let your team travel around the room and look at all of the new airplanes and helicopters. However, there are different rooms, and some of them are separated by impassable walls and locked doors.
Since your team performed so well in the CodeQuest competition, the supervisors let your team choose which room to tour. You can only go in one room during the tour.
Your task is to figure out the maximum number of aircraft that you can see, if you visit the optimal room on your team's private tour.
The Lockheed Martin facility that the competition is taking place at can be represented as a 2D grid.
The first line of input contains two space-separated integers $$$n$$$ and $$$m$$$: the number of rows and columns of the grid representation of the facility, respectively.
The next $$$n$$$ lines each contain $$$m$$$ characters: the 2D top-down view representation of the Lockheed Martin facility.
If a character is a single dot ("."), then the space in the grid is empty space that can be walked through. If a character is an x ("X"), then the space in the grid is an impassable wall. If a character is a p ("P"), then the space in the grid is an airplane or helicopter. Note that you can walk through a space with an aircraft.
You cannot walk diagonally.
Output a single positive integer $$$p$$$: the maximum number of aircraft that you can see on your facility tour, only visiting one room.
5 5 P.X.. ..XP. XXXX. ...XP ...X.
2
11 10 XXXXXXXXXX X..P.....X X.XXX....X X...X....X X...XX...X X.X.PX.P.X X.XXXX...X X....PXXXX XXXXXX.P.X XPPP.X.PPX XXXXXXXXXX
4
You have placed $$$n$$$ pins on a bulletin board, and a rubber band. You want to place the rubber band around a certain subset of the pins, such that there aren't any pins inside of the rubber band that aren't touching the rubber band. In other words, the rubber band must touch all of the points inside of it.
Figure out the largest number of pins that you can choose, and still satisfy the condition described above.
The first line of input contains a single positive integer $$$n$$$, less than or equal to 7: the number of pins.
The next $$$n$$$ lines each contain two space-separated integers $$$x$$$ and $$$y$$$: the x and y coordinates of each pin, respectively.
Output a single positive integer $$$k$$$: the size of the largest subset of pins that you can wrap the rubber band around, such that the rubber band is touching all points inside of the rubber band.
5 4 1 3 -3 0 0 1 -2 2 2
5
6 0 0 2 0 4 0 2 2 2 -2 2 -1
4
6 0 0 2 0 4 0 2 2 2 -2 3 -1
5
Ken Ken is a number puzzle created in 2004 by Tetsuya Miyamoto.
Like Sudoku, Ken Ken involves placing numbers into an n by n grid, and it requires each row and column to contain distinct integers from 1 to n. n will be equal to 5 for this problem.
Additionally, each of the n * n cells in the Ken Ken puzzle is assigned to a "cage" consisting of one or more cells. If a cage consists of multiple cells, they have to form a single block of cells connected vertically or horizontally, but not diagonally. For example, an L-shaped cage, or a 2 by 2 square cage would be valid, but a cage consisting only of two cells at the opposite end of the board would not be valid. Usually, cages don't have more than 4-5 cells (although there is no upper limit).
For each cage in the puzzle, if it consists of only one cell, the cage will simply be assigned a number, indicating which number is placed in the cage in the final solution. This is called a "freebie".
Otherwise, each cage with two or more cells is assigned a math operation. All of the cells in the cages must complete the math operation successfully. For example, if a cage had the operation "9+", the total sum of the numbers in the cells of the cage would have to sum to 9. If a cage had the operation "120x", the total product of the numbers in the cage would have to be 120.
Cages can also have subtraction or division operations. These types of cages have to have exactly two cells. For subtraction, the difference of the two numbers in the cage must equal the given number. For example, if a cage had the operation "2-", then the numbers could be 3 and 1, in any order. They could also be 4 and 2, 2 and 4, 5 and 3, and so on. Cages with division work similarly. The number in the cage must equal the quotient of the higher number divided by the lower number. For example, for a "2/" cage, the numbers could be 1 and 2, or 2 and 1, or 4 and 2, and so on. As such, the required number of a cage will always be a positive integer.
Note that although all rows and columns must consist of distinct numbers, cages do not have to.
Here's an example of what an unsolved Ken Ken puzzle looks like:
And here's the solution to the same Ken Ken puzzle:
Your task, as you might have guessed, is to write a program to solve a Ken Ken puzzle. All of the Ken Ken puzzles will have been taken from a book of Ken Ken puzzles, meaning that they will all be potentially solvable by a human.
Good luck!
The first line of input consists of a single positive integer $$$n$$$: representing the size of the Ken Ken puzzle (the puzzle will be an $$$n$$$ by $$$n$$$ puzzle). $$$n$$$ will be equal to 5 for this problem.
The next lines will contain a grid representation of the Ken Ken puzzle. Each cage will be marked off with pipes ("|") and hyphens ("-"). See the example cases for the exact formatting of the input.
The cell in each cage closest to the top of the puzzle will contain the math operation. If two cells in a cage are the same distance from the top of the puzzle, the leftmost one will contain the math operation.
Output $$$n$$$ lines, each consisting of $$$n$$$ integers: the solution to the Ken Ken puzzle.
5 |---|---|---|---|---| |2- |12+|2 |10x|2/ | | | | | | | | | |---| | | | | |12x| | | | | | | | | |---| | | |---| |3- | | | |20x| | | | | | | | |---| |---| | | |20+| | | | | | | | | | |---| |---| |---| | | | | |-------------------|
34251 53412 15324 42135 21543
5 |---|---|---|---|---| |40x |2- | | | | |---|---|---|---|---| |8+ |24x |8+ | | | | | | |---|---|---| | | |8+ | | | | | | |---|---| |---|---| |5+ | |15x | | | | | |---|---| |---|---| |2- | |2/ | | | | | |---|---|---|---|---|
25431 12345 34512 41253 53124