I’ve tried to format your code for you, but I’m not sure if that’s what you have right now. Please check and edit it if necessary. Thanks.
yes that’s it
I caught how the editor is working!!
Good!
For the first test case, please observe the following points:
• In round 1, the highest mountain is index 0.
• In round 2, the height of mountain index 0 becomes 0 (as you’ve shot it in round 1).
• So, after reading the first height,
@ the list mountain becomes [[0, 0]]
@ done = 1
• All other mountains have a height greater than 0, so they all fall into the “else” block.
• However, as done = 1, the “if” block inside the “else” block is never executed.
Thanks, I was lost
Manage to write it in python and translate it in c++
Hi, I am new here. Can someone please explain why when i replace “max” with “0” in the if statement it outputs “7”?
Shouldn’t imax be 0 since the range is set (0,8)?
{
while True:
max = 0
imax = 0
for i in range(0,8):
h = int(input())
if h > 0:
max = h
imax = i
print(imax)
}
I don’t understand my problem.
The error is “Timeout: your program did not write to the standard output in due time.”, and my code is :
// game loop
while (TRUE)
{
$targer = 0;
$max = 0;
for ($i = 0; $i < 8; $i++)
{
// $mountainH: represents the height of one mountain.
fscanf(STDIN, "%d", $mountainH);
if($max < $mountainH){
$max = $mountainH;
$target = $i;
}
}
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug: error_log(var_export($var, true)); (equivalent to var_dump)
echo($target); // The index of the mountain to fire on.
}
?>
Is there anyone help me please ?
There’s a typo in one of the variable names.
Thank you for your answer, but I fixed the variable names, and I still have the same problem…
I found the solution; for some, it’s important to remember to include “\n” when concatenating with your result. Without this, the problem “Timeout: your program did not write to the standard output in due time” occurs. I don’t understand why. Is there anyone with an answer for that?
Oh yes, that too.
The referee needs the “\n” so that it knows you have completed your output.
Yes, you’re right, it was my first puzzle, I didn’t understand that .
In any case, thank you for your answers.
LOL, I had the same issue. I was so confused for 10 minute and my print statement wasn’t making any sense either. I think the wording of the problem was confusing and it should just get straight to the point.
Been trying to learn coding for years, I can never find a website that actually teaches you how to code. You need a lot of beginners experience first before being able to do any of this. It’s a lot of throwing you in the depend with no examples of how the code should be written or explaining what to write or how
every time the var MountainH is getting a values from the list of the Mountains from 0 to 7 index in the infinit loop.
Hi,
can someone explain to me why I have to declare the variables in the gameloop and not above it. If the variables are outside the gameloop, they are not filled.
That’s because each round gives you a new set of eight values of the mountain heights, and you need the new values to determine the answer.
But depending on the programming language you use and how you structure your code, you may be able to declare some variables outside the game loop, and reset them inside the game loop at the beginning of each round.
if(mountainH > max) {
max = mountainH
imax = i
}
can someone explain me what is this code doing (step by step please )??
Line 1: Tests if the current height is higher than the maximum height.
Line 2: If yes, changes the value of the maximum height by the current height.
Line 3: Stores the index of the current height (that is now the maximum height).
Line 4: End of the code block.
Hi there,
Sure, I’d love to explain!
This code fragment compares mountainH
with max
. If mountainH
is greater, max
is updated to the new highest value and imax
takes the value of i
, which probably represents the index of the current highest mountain.
BR,
David
I didn’t understand what happened, he just didn’t give an answer, I know the answer is much simpler than that but I wanted to try it my way.
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int x=0,cont=0,conta;
int[] mountainH = new int[9];
while (true) {
for (int i = 0; i <= 8; i++) {
mountainH[i]=in.nextInt();
}
x=mountainH[0];
cont=0;
conta=0;
for(int max:mountainH){
if(max>=x){
x=max;
cont=conta;
}
conta++;
}
System.out.println(cont);
}
}
Try i < 8
instead of i <= 8
.