Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
number problem
#1
Hi,

How to write a program which reads integers from the standard input (until it gets a negative number) and puts them into an array. After that it calls processArray on the array, and then prints the value that is returned to standard output.


Currently, processArray does not do anything useful - it just returns 0.

we have to change processArray so that it finds the longest losing streak in the array, and returns the loss of the streak.

A sequence of consecutive numbers in which each number is less than or equal to the previous number is called a losing streak. The difference in value between the last number of the streak and the first number of the streak is known as the loss.

For example, if these numbers were provided on the standard input:


3
6
36
32
32
121
66
24
22
371
661
6
4
8
-1

The losing streaks in this sequence are 36, 32, 32, and 121,66,24,22, and 661,6,4, and the corresponding losses are 4 and 99 and 657. In this case, the 2nd streak with 4 numbers is the longest, so your program should print it's loss:

99

we need to make sure that program prints a single integer to the standard output and nothing else. there should not be any Any unnecessary printf/println/putchar etc.
Reply


Messages In This Thread
number problem - by jk91 - Apr-28-2020, 05:38 PM
RE: number problem - by micseydel - Apr-28-2020, 05:39 PM
RE: number problem - by deanhystad - Apr-28-2020, 06:34 PM
RE: number problem - by perfringo - Apr-29-2020, 05:14 AM
RE: number problem - by Shahmadhur13 - Apr-29-2020, 05:27 AM
RE: number problem - by Shahmadhur13 - Apr-30-2020, 09:09 AM
RE: number problem - by Shahmadhur13 - May-03-2020, 02:33 PM
RE: number problem - by jk91 - May-03-2020, 08:05 AM
RE: number problem - by ndc85430 - May-03-2020, 08:08 AM
RE: number problem - by jk91 - May-03-2020, 09:28 AM
RE: number problem - by ndc85430 - May-03-2020, 01:07 PM
RE: number problem - by deanhystad - May-03-2020, 08:25 PM
RE: number problem - by jk91 - May-07-2020, 05:07 PM
RE: number problem - by ndc85430 - May-08-2020, 07:02 AM
RE: number problem - by jk91 - May-08-2020, 07:14 AM
RE: number problem - by buran - May-08-2020, 07:22 AM
RE: number problem - by ndc85430 - May-08-2020, 07:25 AM
RE: number problem - by jk91 - May-16-2020, 07:52 AM
RE: number problem - by ndc85430 - May-16-2020, 08:37 AM
RE: number problem - by jk91 - May-16-2020, 08:58 AM
RE: number problem - by jk91 - May-30-2020, 09:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with number of rows containing null values PythonSpeaker 3 2,257 Nov-23-2019, 06:53 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020