Hello, I’ve an issue with the C++ code linked to the temperatures. From the batch of test proposed, all test cases are correct but when I tried to submit my code, 2 test cases failed but I don’t have any traces in order to find what’s wrong with my c++ code.
The one linked to the min and the max.
When you declared a variables to the min, you have to add a value too…
Let it be a real temperature value, even if it is a minus… without math.abs… or something like this.
Bonjour,
J’ai une question concernant les validateurs, je n’ai que le 3eme de non validé : “5526 alone”.
Qu’est-ce qu’il signifie ? Merci pour vos réponses.
I’m confused, shouldn’t we be considering that the values given might not be integers, what if there are invalid data in the input string? It’s a string after all not an int.
If I simply split the string by " " then I am assuming each entry is valid, am I not?
I get that we “know” the values are ints, but in the real world, we can’t be sure.
I have a problem submitting my solution to this exercise.
It has been written in Java language.
One variable seems to have a correct value, when i try to access it through println, but the tests fail anyway with the following error :
"error: cannot find symbol
if(absActualTemp < absPreviousTemp) {
^
"
Here is the source code :
StringTokenizer st = new StringTokenizer(temps, " ");
List<Integer> temperatures = new ArrayList<Integer>(n);
int previousTemp = Integer.parseInt(st.nextToken());
int actualTemp = Integer.parseInt(st.nextToken());
int absActualTemp = Math.abs(actualTemp);
int absPrevioustemp = Math.abs(previousTemp);
int result = previousTemp;
if (n == 0) {result = 0; }
for (int i=0;i<(n-1);i++) {
if(absActualTemp < absPreviousTemp) {
result = actualTemp;
} else if(absActualTemp == absPreviousTemp) {
if (Integer.signum(actualTemp) > 0) {
result = actualTemp;
}
}
previousTemp = actualTemp;
absPreviousTemp = absActualTemp;
actualTemp = Integer.parseInt(st.nextToken());
absActualTemp = Math.abs(actualTemp);
}
This isn’t “the real world”. This is an exercise. In the context of this exercise, you can be assured that the inputs follow the input specification. There is nothing wrong with trusting that the inputs are as described.
The puzzles have a data contract. In “the real world” you need to be prepared for a data provider to possibly break the contract. Here, the input is static and has already been tested by thousands of people before you. If the input doesn’t adhere to the contract, then you should complain to CG, and they will fix it. In “the real world”, you would need to somehow handle bad data. Here, you can just yell loudly and move on to another puzzle until it’s fixed.
I’ve the same issue in javascript, and i get the same score too. Can you reproduce this test cases inside the code editor? i think, maybe the -273 alone test case contain and empty space or some character (maybe the integer that you are expecting is not a number), so if you’re using some kind of split method, this test cases cannot pass.
It seems to be lacking a test case where there are positives and negatives, and a negative is the answer. Every test seems to have only positives, only negatives, or if they’re mixed, the answer is always positive.
Eg. (7 -2 14 -7 22)
Correct answer here would be -2. You could have code that returns 7 or -7 because they’re equal and you were testing for that to make it positive 7, and this would be wrong but you aren’t marked down for it.
I was surprised anybody thought about the case for two negatives and it got me. I was being dumb. I think this might catch somebody now and then too.
Edit: Also, the hardest part of this was figuring out how to get at the numbers in the string, which I don’t think was the intention. Compared to that, the rest was easy.
It was difficult to obtain a 100% score. Al tests succeeded, but validation rejected my last solution several times. I had to jiggle around with the code a couple of times, before getting a 100% score. Yet I don’t see any real difference between my original and my final code.
I success these puzzle 100% in python3 code, but when I send it for final validation, codingame give me only 90% because it’s wrong for the case where the temperature is empty.
But with the case 6, during the direct test, my code work when the temperature is empty and I print 0 correctly! I do a test on the temperature to know if it’s empty.