TÓPICO
5% error (Javascript)
mrahman304 perguntou 3 years ago
So it shows 5% error. I tried uDebug. The input/output macthes.
Dúvida resolvida. Código removido.
The same doesn't happen with C. is it a js bug?
Este tópico foi resolvido e não pode receber novas respostas.
-
mrahman304 respondido 3 years ago
@Gabriel ... Thanks Bro, It worked. So the map() fucntion was the culprit.
-
GabrielMartins respondido 3 years ago
I did it using an input method inside the loop:
var values = input.split('\n'); var elem = parseInt (values.shift ());
I think your method should work, but the language is still in beta, so it is normal for errors to occur.
-
mrahman304 respondido 3 years ago
@Gabriel, your inputs are in one line .... uri has it in 5 line.
is it possible to talk bro.... fb , zoom anything...just need 5 minute of your time?
-
mrahman304 respondido 3 years ago
@Gabriel
Have you tried submitting it? Can you share me the code :D
-
mrahman304 respondido 3 years ago
@Gabriel
My inputs are fine .... here is an example of input....
[ -1, 0, -4, -6, 19 ]; //just console.logged it
the whole code
var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var lines = input.split('\n'); let elem = lines.map(e => { return parseInt(e); }); let i = 0, even = 0, odd = 0, pos = 0, neg = 0; for (i = 0; i < elem.length; i++) { if (elem[i] === 0) { even++; continue; } if ((elem[i] % 2) === 0) even++; else odd++; if (elem[i] < 0) neg++; else if (elem[i] > 0) pos++; } console.log(even + (' valor(es) par(es)').toLowerCase()); console.log(odd + (' valor(es) impar(es)').toLowerCase()); console.log(pos + (' valor(es) positivo(s)').toLowerCase()); console.log(neg + (' valor(es) negativo(s)').toLowerCase());
-
GabrielMartins respondido 3 years ago
This solved the compilation error in Node.js for me:
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
Also, your data entry function are reading just 1 int.
-
mrahman304 respondido 3 years ago
@Gabriel
I trid it ... still 5% error
var input = require('fs').readFileSync('stdin', 'utf8'); var lines = input.split('\n'); let elem = lines.map(e => { return parseInt(e); }); let i = 0, even = 0, odd = 0, pos = 0, neg = 0; for (i = 0; i < elem.length; i++) { if (elem[i] === 0) { even++; continue; } if ((elem[i] % 2) === 0) even++; else odd++; if (elem[i] < 0) neg++; else if (elem[i] > 0) pos++; } console.log(even + (' valor(es) par(es)').toLowerCase()); console.log(odd + (' valor(es) impar(es)').toLowerCase()); console.log(pos + (' valor(es) positivo(s)').toLowerCase()); console.log(neg + (' valor(es) negativo(s)').toLowerCase());
-
GabrielMartins respondido 3 years ago
I recommend that you adjust the I/O method to as exemplified here: https://www.urionlinejudge.com.br/judge/en/faqs/about/examples