Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

number issue

 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It 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.

So How can we write program to resolve this issue?



Thanks..
 
Saloon Keeper
Posts: 12022
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should know by now that we don't hand out solutions.

What have you tried? What are you stuck on?
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried below in python but in php 7 how to convert it ?



also it's giving these errors upon executing on python 3 platform:-

upon executing above program on python 3 platform getting below errors:-

Sorry. Your solution is incorrect. Please try again. Feedback for your solution:

The function does not work as expected. Please check the following carefully:

Please ensure that the program produces the expected output as given in the problem
Make sure your answer contains a full, working program.
Make sure your processArray function/method is returning the appropriate value
If you wrote a C program, make sure that the program is not using any functions not found in the standard C library. Specifically, it should not use any Microsoft or Turbo C specific functions like getch or clrscr or conio.h
Make sure that the program is not printing anything extra to the output
Make sure that the program is not trying to read any input. No scanf or getc

 
Marshal
Posts: 15635
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you haven't exactly followed this instruction, have you?

"make sure that program prints a single integer to the standard output and nothing else"

And it looks like you've also violated this stipulation:

"Make sure that the program is not trying to read any input"
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it would have been nice if someone would have corrected the same.


Thanks..
 
Stephan van Hulst
Saloon Keeper
Posts: 12022
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again... what have you tried? We're not going to convert it to PHP for you.
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic