Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.
Input
The first line contains a single integer N.
Next N lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes coefficient of Pi.
Output
Print the polynomial in the format Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0, where Pi's are powers in decreasing order, Ci is coefficient, and C0 is constant. There will be space before and after the plus or minus sign.
If the coefficient is zero, then don't print the term.
If the term with the highest degree is negative, the term should represent -Cix^Pi.
For the term where power is 1, represent it as C1x instead of C1x^1.
If the polynomial degree is zero and the constant term is also zero, then print 0 to represent the polynomial.
For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.
Sample Input
5
0 2
1 3
2 1
4 7
3 6
Output:
7x^4 + 6x^3 + x^2 + 3x + 2Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.
3 3
1 2 3
5 10 11
15 20 30
Ordered Matrix
Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.Output
The output should be M lines containing the ordered matrix.
Note: There is a space at the end of each line.Explanation
For example, if the given M is 3 and N is 3, read the inputs in the next three lines if the numbers given in the next three lines are the following.
1 20 3
30 10 2
5 11 15By ordering all the elements of the matrix in increasing order, the ordered matrix should be
1 2 3
5 10 11
15 20 30Sample Input 1
3 3
1 20 3
30 10 2
5 11 15
Sample Output 1
1 2 3
5 10 11
15 20 30
Sample Input 2
2 5
-50 20 3 25 -20
88 17 38 72 -10
Sample Output 2
-50 -20 -10 3 17
20 25 38 72 88
For Input:
2
1 2
3 4
R 90
Q 0 0
Q 0 1
R 90
Q 0 0
U 0 0 6
Q 1 1
-1
Initial Matrix
1 2
3 4
For R 90, clockwise rotation by 90 degrees, the matrix will become
3 1
4 2
For Q 0 0, print the element at row index 0 and column index 0 of A, which is 3.
For Q 0 1, print the element at row index 0 and column index 1 of A, which is 1.
Again for R 90, clockwise rotation by 90 degrees, the matrix will become
4 3
2 1
For Q 0 0, print the element at row index 0 and column index 0 of A, which is 4.
For U 0 0 6, update the value at row index 0 and column index 0 in the initial matrix to 6.
6 2
3 4
After updating, we need to rotate the matrix by sum of all rotation angles applied till now
4 3
2 6
Next for Q 1 1, print the element at row index 1 and column index 1 of A, which is 6.
So the output should be
3
1
4
6Add two polynomials
Given two polynomials A and B, write a program that adds the given two polynomials A and B.Input
The first line contains a single integer M.
Next M lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes co-efficient of Pi for polynomial A.
After that next line contains a single integer N.
Next N lines contain two integers Pj, Cj separated with space, where Pj denotes power and Cj denotes co-efficient of Pj for polynomial B.
input:
4
0 5
1 0
2 10
3 6
3
0 1
1 2
2 4
output:
File "main.py", line 12
for j in range(m);
^
SyntaxError: invalid syntax
expected output:
6x^3 + 14x^2 + 2x + 6
please rectify it!!
i am using python 3.9
Ordered Matrix
Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.
input:
3 3
1 20 3
30 10 2
5 11 15
output:
Traceback (most recent call last):
File "main.py", line 1, in <module>
M=int(input())
ValueError: invalid literal for int() with base 10: '3 3'expected output:
1 2 3
5 10 11
15 20 30 input:
2 5
-50 20 3 25 -20
88 17 38 72 -10
expected output:
Traceback (most recent call last):
File "main.py", line 1, in <module>
M=int(input())
ValueError: invalid literal for int() with base 10: '2 5'please rectify it:
Write a program to check the overlapping of one string's suffix with the prefix of another string.
You are given a square matrix A of dimensions NxN. You need to apply the below given 3 operations on the matrix A.
Rotation: It is represented as R S where S is an integer in {90, 180, 270, 360, 450, ...} which denotes the number of degrees to rotate. You need to rotate the matrix A by angle S in the clockwise direction. The angle of rotation(S) will always be in multiples of 90 degrees.
Update: It is represented as U X Y Z. In initial matrix A (as given in input), you need to update the element at row index X and column index Y with value Z.
After the update, all the previous rotation operations have to be applied to the updated initial matrix.
how to print vowels and consonants and spaces are not counted
Case Conversion
Given a string in camel case, write a python program to convert the given string from camel case to snake case.Input
The input will be a single line contain a string.Output
The output should contain the given word in snake case.Explanation
For example, if the given word is "Python Learning" in camel case, your code should print given word in snake case "python_learning".
Sample Input 1
Python Learning
Sample Output 1
Python_learning