Check Anagrams
For a given pair of words check if they are anagrams. Print
YES if they are anagrams, or else print NO.Two words are anagrams if one word can be obtained by the rearrangement of the characters in another word.
INPUT: The first line of the input contains an integer
OUTPUT: The output should have the status of each of the
N pairs that are given in the input.All the statuses are separated by space.
Given pairs
dew wed
race care
In the word
dew, characters can be rearranged in the reverse order to get the word wed.So both the words are anagrams. The status of this pair is YES.
From the word race, when the characters r and c are swapped we will get the word care. So both the words are anagrams. The status of this pair is
YES.
Sample Input 1
2
dew wed
race care
Sample Output 1
YES YES
Sample Input 2
3
part trap
car air
some sum
Sample Output 2
YES NO NO
Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.
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.
For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.
Explanation
If N = 4 If N = 5
If N=4
polynomial represents "6x^3+10x^2+5"
If N=5
polynomial represents "7x^4+6x^3+x^2+3x+2"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.Explanation
Input
4
0 5
1 0
2 10
3 6
Output
6x^3 + 10x^2 + 5
Input
5
0 2
1 3
2 1
4 7
3 6
Output
7x^4 + 6x^3 + x^2 + 3x +5
Two polynomials A and B are given, add two polynomials A and B
Write a program to input amount and display its annotations.
Matrix Rotations
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. Querying: It is represented as Q K L. You need to print the value at row index K and column index L of the matrix A.
Input Next N lines contain N space-separated integers Aij Next lines contain various operations on the array.
Each operation on each line (Beginning either with R, U or Q). -1 will represent the end of input
you answered like this:
def X_Only(Matrix:list):
for row in Matrix:
for cell in row:
# check if value is not X
if cell!='X':
return False
return True
def sub_size(lent:int):
for start in range(lent):
for stop in range(start+1, lent+1):
yield(start, stop)
def squareAreaWithX(matr:list, M:int, N:int):
maximum_area = 0
for begin_x, stop_x in sub_size(M):
for begin_y, stop_y in sub_size(N):
temp_matrix = [i[begin_y:stop_y] for i in matr[begin_x:stop_x]]
if X_Only(temp_matrix):
x= stop_x-begin_x
y= stop_y-begin_y
if maximum_area < x*y:
maximum_area=x*y
print(maximum_area)
while True:
s = input()
M, N = [int(i) for i in s.split()]
matrix = list([] for i in range(N))
for i in range(M):
matrix[i]=list(input().split())
squareAreaWithX(matrix, M, N)we are getting IndexError: list assignment index out of range error when input is:
8 6
X X X X X X
X X X X X X
X X X X X X
X X X X X X
X X X X X X
X X X X X X
X X X X X X
X X X X X X
Polynomial
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.
Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.
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.
For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.
Explanation
If N = 4 If N = 5
For power 0, the coefficient is 5 For power 0, the coefficient is 2
For power 1, the coefficient is 0 For power 1, the coefficient is 3
For power 2, the coefficient is 10 For power 2, the coefficient is 2
For power 3, the coefficient is 6. For power 3, the coefficient is 6.
For power 4, the coefficient is 7.
polynomial represents "6x^3+10x^2+5" polynomial represents "7x^4+6x^3+x^2+3x+2"Write a program to check the overlapping of one string's suffix with the prefix of another string.Input
The first line of the input will contain a string A.
The second line of the input will contain a string B.Output
The output should contain overlapping word if present else print "No overlapping".Explanation
For example, if the given two strings, A and B, are "ramisgood" "goodforall"
The output should be "good" as good overlaps as a suffix of the first string and prefix of next.
input:
ramisgood
godforall
output:
good
input-2:
finally
restforall
output:
No overlapping