- 1
Can any one solve this :- Array leaders
An array of N numbers is passed as input.The program must print all LEADERS in the array. A number is a LEADER if it is greater than all the numbers to it's right. Note: The right most number is always a leader. input: The first line contains N numbers each separated by space output: The first line contains the LEADERS each separated by space. example: 10 17 4 3 5 2 output: 17 5 2
4 ответов
+ 1
Louis, In the question the number of integer inputs is not given. Check the input in the question.
And can you do that in c++ or c
+ 1
@Samar. I can do it in C, but I dont want to, once you've discovered the joys of Python you aren't interested in anything else.
You won't see Husain Bolt practicing his crawling, he's past that, he now practces running as fast as possible. That was the purpose of showing everyone how simple things are with Python.
If you want to enter the value yourself just change the code to
inp=list(map(int,input().split()))
and enter the numbers with spaces inbetween.
eg: 10 6 88 6 7
P.s. I believe that Ruby has the same power and simplicity that in some instances may surpass Python.
0
#Python
inp=[10,17,4,3,5,2]
inp.append(0)
print([inp[i] for i in range(len(inp)-1) if inp[i]>max(inp[i+1::])])
0
Louis, yes I know that in python it is very easy and to take input in such format.
But currently I am learning c++. So my actual doubt is how to take N input of integers separated by a space whose number of integers (N) is not given.
In python we can do that by
a=input().rstrip()
a=a.split(' ')
for i in range(len a) :
a[i]=int(a[i])
but how to do that in c or in c++