Hi all,
I’m trying to solve this puzzle using Python2. I’m having trouble parsing the input values in “temps” variable. I assumed the input would be integers but it’s behaving as string characters. Am I missing something? Need help getting started.
Use int() to convert:
temps = input()
temps2 = temps.split()
temp = int(temps[ i ]) # i = 0 - N
Thanks @rogerup! I stopped beating my head against the wall and accepted the fact that the inputs were string characters. I was able to solve the puzzle before I saw your response. Your use of .split() looks a lot cleaner than what I did. I still have a lot to learn.
temps=[int(i) for i in input().split()]
Hey, anyone resolved this in c?
We have the inputs in the form of string how to change it to integer array so that some operations can performed on it.
if their is an atoi() like function which can extract all the integers.
Hello guys,
I m trying to perform first test case…
I get
Standard Output Stream:
I parse the input into this [‘1’, ‘-2’, ‘-8’, ‘4’, ‘5’]
clean it with a loop to get absolute values
and find the closest value to 0
but the program finds “]” whereas I have
this result
1
Failure
Found: [
Expected: 1
Hello, Im doing this with Pascal. My code is ok except on the last one (no temperature).
I’ve tried to print out 0 and ‘0’ and got the same error:
Erreurs
An unhandled exception occurred at $00000000004272D2 :
Sortie standard :
¤RED¤Fail§RED§Found: "A"Expected: “0”
Salut, si quelqu’un pouvait me dire et m’expliquer ce qui cloche dans mon code ou mon algo ce serait sympa ^^
var n = parseInt(readline()); var temps = readline(); var valeurPos=5526; var valeurNeg=-273; var split=temps.split(" ");
printErr(split);
for(n=0; n<=10000; n++){
for(i=0; i<split.length; i++) { if(split[i]<valeurPos && split[i]>=0){ valeurPos=split[i]; printErr(valeurPos); } if(split[i]>valeurNeg && split[i]<=0){ valeurNeg=split[i]; printErr(valeurNeg); } } }
if(-valeurNeg>valeurPos){ print(valeurPos); } else if(-valeurNeg<valeurPos){ print(valeurNeg); } else if(-valeurNeg==valeurPos) { print(valeurPos); }
Okay, now it seems to me that the topic of this puzzle should be extract integer array from an character string. . Searching is a simple task and the background task “to convert string to array” is more difficult.
Hi guys! I’ve made a code for this puzzle in C# and got 90%… Everything was working ok before I submitted and also tried to simplify it a bit after I got the score to see if it would make any difference, but I still keep getting 90%. I really don’t know why this is happening, particularly since it fails on the third test (choose the right temperature), when the fourth one (choose the right temperature 2), which is fairly similar, works just ok. Any feedback on this would be very much appreciated.
int n = int.Parse(Console.ReadLine());
string temps = Console.ReadLine();
if (temps != "") {
char delimiter = ' ';
string[] newtemps = temps.Split(delimiter);
int max = 5527;
int min = -274;
int final = 0;
for (int i = 0; i<n; i++) {
int num = Int32.Parse(newtemps[i]);
if (num >= 0 && num < max) {
max = num;
}
else if (num < 0 && num > min) {
min = num;
}
}
final = max + min;
if (final <= 0) {
Console.WriteLine(max);
} else Console.WriteLine(min);
} else Console.WriteLine("0");
The third test is “5526 alone”.
Your program should ouput 5526, but it display -274.
I agree that -274 is closer to 0 than 5526, but -274 is not provided in the inputs.
Thanks for the comment! I had forgotten a little detail on the code. I’ve resubmitted it now and got 100%.
Quand dans le résultat du code python:
Échec
Trouvé : 5
Attendu : -
Attendu - ???
Code pas tout a fait fini… mais toujours ce truc bizarre attendu “-”
C’est un signe moins, la réponse attend un nombre négatif.
My code is not working in the IDE but works in GNU GCC
it said segmentation error but works fine for me
http://pastebin.com/Cd0sJRGe
I get a segmentation fault in both the IDE and GCC for your code.
Have you read this part of your code?
+1 pour le fprintf de debug.
Et tu ne peux pas ne travailler qu’avec des valeurs absolues, les températures négatives doivent le rester.