When I code my first test case, and the validators is ok. If i try and code the second one I lose my completion for test case 1. Anyone knows a solution?
You should try to solve the problem in a general way, not for the specific test cases you are provided.
From your message, Iguess you hardcoded the mountains youāre aiming at, your solution should use the inputs given in each turn to determine which mountain to aim at.
You should also check the hints for this puzzle on the left side of the screen.
I did but somewhat I donāt understand better + the fifth hint help me out to identify but I canāt run my code even by respecting hint #5
I get invalid syntax at line 21
21 end if
22 end for
23 print(str(imax))
This is part of pseudocode from hint #5, itās need to be rewritten it according to language you use
Hi _CG_Thibaud! What do you mean?
check my post in this thread 7 days ago
I finished Testcase1 and 2 but I realized that in case 3 has a problem about the height of these mountains.Such as when the spaceship hits mountain 2 ,we must do 2 times to break it from 7 to 4 .Could anyone give me a hint clearly?? .I have already read the hint in the game but couldnāt understand clearly? thatās my code for case1 and 2 !! Thanks in advance!!
import java.util.*;
import java.io.*;
import java.math.*;
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int[] arr = new int[20];
while (true) {
for (int i = 0; i < 8; i++) {
int mountainH = in.nextInt();
arr[i] = mountainH ;
}
int Max = 0;
for (int i = 0; i < 8; i++) {
if (arr[i] > Max) {
Max = arr[i];
}
}
while (Max >= 0) {
for (int i = 0; i < 8; i++) {
if (arr[i] == Max) {
System.out.println(i);
}
}
Max--;
}
}
}
}
Your solution prints every non null mountain id at every turn, and not only the highest one.
In the first two test cases, shooting on a mountain reduces its height to 0, so your first turn printing matches the expected solution.
You should try printing only one mountain id per turn.
Hello, Iām new to this website and also to C++, but I wanted to learn the language. Hereās my solution, I donāt wanāt help with finding a solution as I want to suffer through this on my own, I only have a small question. But hereās my code so far.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <vector>
using namespace std;
int main()
{
// game loop
while (1) {
int answer;
std::vector<int> h;
for (int i = 0; i < 8; i++) {
// represents the height of one mountain.
int mountain_h;
scanf("%d", &mountain_h);
h.insert(h.end(), mountain_h);
while (i >= 7) {
answer = *max_element(h.begin(), h.end());
}
}
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
printf("answer\n"); // The index of the mountain to fire on.
}
return 0;
}
I get this error and Iām not quite sure why, when Googling whether vectors can be used on CodinGame I didnāt see any objections and I even found a post that contained some helpful tips and the template the author suggesting using which also had the "include " line.
Hereās my error:
/tmp/Answer.c:5:10: fatal error: vector: No such file or directory
5 | #include
| ^~~~~~~~
compilation terminated.
Any help would be appreciated, thanks.
Iām still stuck with The Descent 02.
Iāve been coding for a long time, except I muddled up in this one. (No bugs.) Itās not really clear to me. Whyād I crash on Mountain 4, if it worked on The Descent 01 (test case) and how are you supposed to land anyways?
Your ship crosses the screen and drops a bomb on one mountain (the highest, print its abscissa) then crosses the screen again a bit lower and drops another bomb and so on until it lands.
thanks!! ^^
How I do turn on the tutorial?
tutorial only exists on the onboarding puzzle: https://www.codingame.com/training/easy/onboarding
There are hints on the top left panel that can help you.
In this situation, x++ and x=x+1 do the same things I think
cin.ignore() could get and delete the āENTERā you typed in the buffer pool.
Hey guys,
Can someone explain me the answer for this puzzle. I saw the answer below in PHP but if someone can explain with words what is happening at each loop especially when the $mountainH is lowest than $highestMountain because for me nothing happened. And I want to know if STDIN read one or several values at each loop?
while (TRUE) {
$highestMountain = 0;
$highestMountainIndex = 0;
for ($i = 0; $i < 8; $i++){
fscanf(STDIN, "%d",$mountainH);
if ($mountainH > $highestMountain) {
$highestMountainIndex = $i;
$highestMountain = $mountainH;
}
}
echo("$highestMountainIndex\n"); // The index of the mountain to fire on.
}
Hello, could someone help the newbie here? Where do I go wrong in understanding the task? I understood that the task is to put System.out.print indexes in the right order? So my code is like this:
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
// game loop
while (true) {
for (int i = 0; i < 8; i++) {
int mountainH = in.nextInt(); // represents the height of one mountain.
}
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
System.out.println("0"); // The index of the mountain to fire on.
System.out.println("1");
System.out.println("2");
System.out.println("3");
System.out.println("4");
System.out.println("5");
System.out.println("6");
System.out.println("7");
System.out.println("0");
System.out.println("1");
System.out.println("2");
System.out.println("4");
System.out.println("5");
System.out.println("7");
System.out.println("3");
System.out.println("6");
System.out.println("5");
System.out.println("2");
System.out.println("1");
System.out.println("3");
System.out.println("2");
System.out.println("3");
System.out.println("1");
System.out.println("6");
System.out.println("5");
System.out.println("7");
System.out.println("1");
System.out.println("5");
System.out.println("3");
System.out.println("1");
System.out.println("1");
System.out.println("3");
System.out.println("3");
and when I run SOUTs piece by piece (putting under comment others) - all of them are correct, but when I hit ātest all casesā it breaks down in case 2. As I noticed - it comes back and starts to run the first portion of SOUTs instead of proceeding with the second. Why is that? What is the solution then if it doesnāt work this way?
Thanks in advance.
As said in the statement the task is to print index of the highest mountain at each turn ā¦ no more no less
Thank you for the the answer. It was stated quite clearly, but am I not doing so with my code? In the 1st case āDescending mountainsā 1st take - biggest is No 0 (sout(index0)). Itās taken down. Then the highest left is No1 (sout(index1)) and etc., etc. till (index7). And it works. I presume, that the same should happen in case 2 āScattered mountainsā, but it is not. It comes back and executes case 1 from index0 to 7. It is not proceeding to case2 for sequence 0, 1, 2, 4, 5, 7, 3, 6 like it is written in my code. Therefore it fails in case 2 on index4.