Temperatures puzzle discussion

Bonsoir ,je ne calcule rien,
je suis arrive a un point ou etant fatigue,
j ai juste affiche les valeurs du tableau en faisant
for(int i=0;i < N;i++)
{printf(’’%d’’,TEMPS[i]);} et j ai constate le trente deux

En fait, je suis allé voir à tout hasard le code de base fourni en C, je dois dire qu’il n’est pas du tout adapté. Le 32 que tu trouves est parfaitement logique vu qu’il s’agit tout simplement de la valeur du caractère espace, à cause du fait que le code fourni ne lit pas vraiment les températures mais une chaîne de caractères…

Il faut remplacer ceci:

char TEMPS[256]; // the N temperatures expressed as integers ranging from -273 to 5526
fgets(TEMPS,256,stdin); // the N temperatures expressed as integers ranging from -273 to 5526

Par une boucle de ce genre :

for(int i = 0; i < N; i++) {
    int temp;
    scanf("%d", &temp);
    ...
}

Tu peux aussi stocker les températures dans un tableau, mais c’est inutile dans ce puzzle.

3 Likes

Ok merci je l ai fait mais j ai une erreur a la validation
mon code ne marche pas quand il n y a qu une seule temperature
j ai fait ceci:
if(N==1)
{
    printf("%d\n",TEMPS[0]);
}

Guys, I got 100% with C++ code. WHY Everybout out of here got fooled by the default wrong code? iostream already handles spaces. I removed the unneeded prank called getline and did a for(int i=0; i<N; ++i) cin >> something. Then the rest was - without even using an array - to do single pass. Cheesy easy!

1 Like

You need to push $s into the array according to your code so that you can get the absolute values and use min() and max().

Hi all!

I’m doing this task in C# and i’ve encountered this problem.

What I want to do is to convert string TEMPS to an array of ints.
But when I try to use “Array.ConvertAll(TEMPS, Int.Parse)”, it says “(…) try specifying the value arguements explicitly”. I can’t understand what am I doing wrong (or it is the wrong way from the beginning?). Obviously, I can’t convert the type of values using just “(int)TEMPS[i]”, but I can’t see the alternative soultion…

So despite meeting the requirements, I can’t seem to earn the point for dealing with -273 alone despite the result not being able to fall below that. What is the check for this? Am I misunderstanding this point? It is infuriating because the code works as intended.

Is it possible that there’s a problem with the Lua validation? My solution works fine for the three “IDE tests” which at the very least should allow it to pass the tests in common with full validation (e.g. no temps). When I submit though, not a single test passes.

Update to my previous issue/question… Converting my Lua solution to C# line by line (i.e. identical solution and output) successfully passes all IDE tests as well as the submit tests.

Same here. Fine for IDE tests, but didn’t go through single validation test.
I have tested my code in lua demo (http://www.lua.org/cgi-bin/demo) with different inputs and the code looks OK, yet it didn’t pass single test.

I dont know why this code:

[EDIT: NO FULL CODE]

cant give me 100% ?
When two temperatures are as close to 0, then the positive wins: {15 -7 9 14 7 12} -> 7 Passed

When two temperatures are as close to 0, then the positive wins 2: {15 7 9 14 -7 12} -> 7 NOT Passed

i can not detect language you use but shouldn’t this part

look like:

and int(i)>0:

?

1 Like

Thanks, that helped. It’s Python :wink:

if blabla:
  k=int(i)
elif blublu:
  k=int(i)

Are you sure that the if/else is useful?

1 Like

No , it’s better to use or statement :smile:

I’m using the javascript version and maybe I’m reading something wrong but on the validation page it seems like maybe there’s a bug where when two numbers are equally close the answer should be positive? It seems like I’m returning the right value for both cases but failing the second test: http://i.imgur.com/1uVCQyW.jpg

Thanks!

Maybe the error is somewhere else.

I am using Javascript.

I find that the readline() function reads the integers as strings.

As a result, the negative sign “-” is a separate element in the array TEMPS. Not sure if this is a bug or a feature.

Example, if the numbers are -5, 2 and -3, the TEMPS variable is ["-",“5”,“2”,"-",“3”] - As you can see the negative sign is a element of its own and messes up my algorithm - the instruction says that I can expect numbers but I get strings!

If the number are -5 2 -3, TEMPS will be ‘-5 2 -3’ with the default code.

Somehow Im passing every single test both in the game and the validation tests, except for the first validation test. Ive traced my program about 18 times and I can’t for the life of me see why those 5 positive numbers would output incorrectly when every other set of numbers works fine, especially when its supposed to be a simple set. Has anyone else had this issue?