given an MxN integer matrix write a program to
Find all zeros and replace them with the sum of their neighboring elements.
After replacing the zeros set all other elements the corresponding row and column with zeros (excluding the elements which where previously zeros)
Note: consider the upper ,lower,right and left elements as neighboring elements
INPUT
The first line of input is two space seperated integeres M and N
The next M lines of input contain N space seperated integers
OUTPUT
the output should be an MxN matrix
sample input 1
3 3
1 2 3
4 0 2
1 1 8
sample output 1
1 0 3
0 9 0
1 0 8
sample input 2
4 5
4 8 0 0 0
4 7 0 9 7
5 5 6 9 8
7 4 3 6 7
sample output 2
0 0 8 9 7
0 0 22 0 0
5 5 0 0 0
7 4 0 0 0
you given a list of prices where prices[i] is the price of a given stock o the i th day write a program to print the maximum profit by choosing a single day to buy a stock and choosing a different day in the future to sell that stock if these is no profit that can be achieved return 0
INPUT
the input is a single line containing space seperated integers
OUTPUT
the output should be an integer
Explanation
in the example the given prices are 7 1 5 3 6 4
buying stocks on day two having price 1 and selling them on the fifth day having price 6 would give the maximum profit which is 6 - 1
so the output should be 5.
sample input 1
7 1 5 3 6 4
sample output 1
5
sample input 2
1 11 13 21 19
sample output 2
20
given a sentence S. and a positive integer N. write a program to shift the sentence by N words to the right
INPUT
The first line pf input is a string S.
The second line of input is an integer N
OUTPUT
The output should be a single line containing the sentence by shifitng the N word to the right
EXPLANATION
in the example the sentence is python is a programming language and N is 2 shift the sentence two words to the right which means the last two words will be moved to the front.
so the output should be programming language python is a
sample input 1
Python is a programming language
2
sample output 1
programming language Python is a
sample input 2
Cats hate water
4
Sample output 2
water Cats hate
Activity #5 – Applying Functions
The output of this activity will be the same as activity #3 but instead you are
required to use a function for the following algorithm:
1. A function for getting the length of each string
2. A function to get the shortest string
3. And a function to get the longest string
Assume that each string has its own unique length.
Sample Run:
Sample Run A
Enter value of X: 3
Enter string value: a
Enter string value: ab
Enter string value: abc
a - total length is 1
ab - total length is 2
abc - total length is 3
The shortest string is 1
The longest string is 3
Sample Run B
Enter value of X: 4
Enter string value: chico
Enter string value: strawberry
Enter string value: banana
Enter string value: guyabano
chico - total length is 5
strawberry - total length is 10
banana - total length is 6
guyabano - total length is 8
The shortest string is chico
The longest string is strawberry
Activity #3 – Strings and Lengths
Create a program that will accept an integer X from the user, followed by X
number of strings. The program will then print each string followed by the length of
each string. Then the program will print the shortest and the longest string.
Assume that each string has its own unique length.
Sample Run:
Sample Run A
Enter value of X: 3
Enter string value: a
Enter string value: ab
Enter string value: abc
a - total length is 1
ab - total length is 2
abc - total length is 3
The shortest string is a
The longest string is abc
Sample Run B
Enter value of X: 4
Enter string value: chico
Enter string value: strawberry
Enter string value: banana
Enter string value: guyabano
chico - total length is 5
strawberry - total length is 10
banana - total length is 6
guyabano - total length is 8
The shortest string is chico
The longest string is strawberry
Activity #2 – Smallest and Divisibility
Create a program that will accept 3 integers from the user. Then the program
will print the smallest integer.
The program will also check if the average of the 3 numbers are divisible by 2, 3,
4 and 5. Each divisibility check will output either “The average is divisible by X” or
“The average is not divisible by X”. Each output is separated by a new line.
If the average is not divisible by 2, 3, 4 and 5 the program must output “The
average is not divisible by 2, 3, 4 and 5”.
Sample Run:
Sample Run A
Enter first value: 2
Enter second value: 5
Enter third value: 9
Smallest value is 2
The average is nor divisible by 2
The average is not divisible by 3
The average is not divisible by 4
The average is divisible by 5
Sample Run B
Enter first value: 13
Enter second value: 14
Enter third value: 13
Smallest value is 13
The average is not divisible by 2, 3, 4 and 5
Roll the Dice, where each dice has from 1 to 6 dots on each side. Two dice will be rolled. Use the random function to generate a random integer between the beginning and ending range of dot possibilities.
Your program should generate a random number. Then display a message to prompt a player to enter his/her name and then guess the number. They have 5 chances to get the number correct. If they guess the right one, display to them that they guessed the correct number in the number of guesses. If they did not guess itin 5 attempts, display a message telling them they were not successful in guessing the correct number and tell them which number it was. Allow the player to play again.
Describe the difference between a chained conditional and a nested conditional. Give your own example of each. Do not copy examples from the textbook.
You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.
Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.
Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.
Formula to convert from Kelvin K to Celsius C is C = K - 273.
Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively.
The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space.
The output contains temperature in Celsius, Fahrenheit and Kelvin scales in each line in the format similar to input and the value of the temperature is rounded to 2 decimal places.
New Year Countdown