Menu Close

Program to replace every element on right side

Write a program to replace every element with the greatest element on right side

A = list(map(int,input("Enter the numbers: ").split())) 
#map returns the object.It passes elements from 2nd arguement to 1st.

N=len(A)

for i in range(N):
	temp=A[i]
	for j in range(i,N):
		if A[j]>temp:
			A[i]=A[j]
			break

print(A)



'''
Input:
	Enter the numbers: 16 17 4 3 5 2
Output:
    [17, 17, 5, 5, 5, 2]
'''

Scrshot


Output:
Enter the numbers: 16 17 4 3 5 2
[17, 17, 5, 5, 5, 2]

Output:
Enter the numbers: 22 550 60 30 20
[550, 550, 60, 30, 20]

Output:
Enter the numbers: 65 65 32 10
[65, 65, 32, 10]

Output:
Enter the numbers: 5 6 2 0 1
[6, 6, 2, 1, 1]

Output:
Enter the numbers: 68 95 45 2 10
[95, 95, 45, 10, 10]


More Codes to Fcuk


Explore