- 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

25th Feb 2018, 5:03 AM
Samar
Samar - avatar
4 Antworten
+ 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
25th Feb 2018, 5:23 PM
Samar
Samar - avatar
+ 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.
25th Feb 2018, 6:57 PM
Louis
Louis - avatar
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::])])
25th Feb 2018, 11:08 AM
Louis
Louis - avatar
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++
26th Feb 2018, 5:08 AM
Samar
Samar - avatar