Temperatures puzzle discussion


#562

What’s the temperature closest to 0 between -10 and -10?


#563

That’s -10.


#564

:sweat_smile:


#565

So I’m new to Java and I need help figuring this out. I can’t even get past the first test. I see a lot of examples in this forum that use things like “split” and “parse”. I’m don’t know what these commands do or if they’re supported by Java. Could anyone point me in the right direction of what I’m doing wrong? The output just says:
Standard Output Stream:
1
-2
-8
4
5
Failure
Found: -
Expected: Nothing

class Solution {

public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt(); // the number of temperatures to analyse
    for (int i = 0; i < n; i++) {
        int t = in.nextInt(); // a temperature expressed as an integer ranging from -273 to 5526
        int min = 10001;
        int abst = (Math.abs(t));
   
   
   
    if (abst <= min) {
        min = t;
    }

    // Write an action using System.out.println()
    // To debug: System.err.println("Debug messages...");

    System.out.println(min);
    }
}

}


#566

You are supposed to print only one number but you are printing a number every loop iteration


#567

Hello everybody!
I can’t solve the problem. Could help me? It is task “alone 5526”. I have solved 90% but I want to do it all. Please, advise me something.


#568

what is the output if you have only one input which is 5526 ?


#569

Hello everyone,

I’m facing issues with solving this puzzle. I really don’t see why my code would always output 0. I have two arrays, one for positive and one for negative numbers, which have a size limit of n. Then there are counters for both of them (int) and a boolean which is set false at first which is set true when either both counts are 0 or there is a temperature of 0. The counts get updated in this fashion (within a for loop, t is the scanned temperature input):
if (t > 0)
{
tempp[countp] = t;
countp++;
}
Same for the negative temperatures, the condition is t < 0 then and the array and count for negative numbers is used.
After the for loop I sort the arrays using Arrays.sort.
And this is all that could output anything:
if ((tempn[0] * -1) < tempp[0] && (countn > 0))
{
System.out.println(tempn[0]);
}
else if (tempp[0] < (tempn[0] * -1) && (countp > 0))
{
System.out.println(tempp[0]);
}
else if (zero == true)
{
System.out.println(0);
}
Any ideas?

Edit:

Rereading the introduction, I noticed that the second line is supposed to be a string of numbers, while the auto-generated code in Java tries to read an int if I get this right:

int t = in.nextInt(); // a temperature expressed as an integer ranging from -273 to 5526


#570

The default code will read an array of int from the String. You do not need to parse the String again. You still need to prepare an array to store the int values for processing after the loop.


#571

I was so close to giving up but at least I got the test cases right in the end, but didn’t pass the first 3 validators… And my code is a mess, several arrays and counters and conditions and loops and stuff… This was far too hard to be easy…
The array bounds were a problem with two arrays, so probably the better way would have been to use only one instead of three in the end, but I wouldn’t have known how

Edit: I was brave enough to press the reset button and it took me 20 minutes to get to 100%… guess sometimes it’s good to throw everything away


#572

Probably 5526.


#573

What if “0” is part of the input set? Should “0” be the answer?


#574

Hi I have the same issue. But weirdly the output is

Standard Output Stream:

-273

Failure
Found:

-…

Expected:

Nothing


#575

When you see an error about “Nothing”, it means you are either missing a carriage return or have too many of it in your answer.


#576

Thanks for the info, I didn’t know what a carriage return was so I googled and found that this is \r and it’s like \n. By the way my code is in C++. I don’t use any of those in my code so that would mean that I am missing a \n or \r. How is that even possible ? That would mean that return carriages are mandatory sometimes ? Sorry for my confusion but as you guessed I’m pretty new to coding :-/
If anyone has another clue for me, it would be really appreciated, thanks :wink:


#577

There are many ways to output a CR. Most puzzles here expect one CR (not more, not less) after an output line.

In C++ you can output the answer (if your answer is in variable n) like this:
cout << n << endl;

Btw, C++ also accepts C codes. You can do it in C style:
printf("%d\n", n);


#578

Same here, i display “1” but
Failure
Found: a…
Expected: 1


#579

And there is nothing that could print an a in your code? I sometimes forgot the auto generated print statement somewhere down in my code

The reason why my code printed 0 instead of 1 was that I sorted an array which had a higher size than it had numbers in it, so the empty spaces just turned into 0 and that was the first value in the array. That still wouldn’t start with a, though…


#580

Bonjour,

Voila, j’ai 90% de réussite, le test 5526 alone ne passe pas.

Le truc, c’est que le -273 alone fonctionne bien, je ne vois pas d’erreur dans mon code, et quand je rentre en dur 5526 pour le input, le résultat affiché est bien 5526.

J’aurai raté quelque chose ? ^^

//

Hi,
I don’t understand why i didn’t get 100%.
5526 alone test failed.
But all other are good even -273 alone

When i put myself 5526, the result is correct, but not with the test.

Did I miss something ? ^^


#581

I don’t know why it works while hardcoding 5526 in input, but during the validator, your code outputs: -5526 :slight_smile: