If it is the urionlinejudge even, maybe you have selected C (gcc)
instead of Javascript (up to another language) in the combobox, as per image:
Probably should be:
So I think the code should be this, because they who will pass the values to A and B through stdin
:
Notes that urionlinejudge automated tests do not accept index, such as lines[0]
and lines[1]
to pick up the lines, so I used .shift
, that removes an item from the variable and copies it to the desired variable, thus:
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var a = parseInt(lines.shift());
var b = parseInt(lines.shift());
var X = a + b;
console.log('X = ', X);
In case it is the urionlinejudge in Portuguese already seems to ask variable SUMMING UP:
Read two integer values, in the case of variables A and B. Next, calculate the sum between them and assign to the variable SOMA. Then write the value of this variable.
Then change to this:
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var a = parseInt(lines.shift());
var b = parseInt(lines.shift());
var SOMA = a + b;
console.log('SOMA = ', SOMA);
A very important detail, apparently you should leave a line break at the end of the script, because without this is what causes the error "Presentation Error"
that you quoted, according to the message:
don’t Forget to print the end of line, otherwise you will receive "Presentation Error"
So instead of this:
Add the new empty line (line break) like this:
After adding the line break at the end now appeared correctly:
I believe you can get [Dit] your question by improving the title. Something like "solution error" doesn’t say much about the real problem and context of your question. Read more on How to choose a good title? Take the opportunity to make the [tour] by the site.
– Woss
Okay. I’ll change it. Thank you.
– Lucas Cardoso
Which website of this exercise?
– Guilherme Nascimento
@Guilhermenascimento would say it’s the URI 1003.
– Woss
As for the error, probably because you are not actually reading the values, but rather defining them as constants.
– Woss
@Lucascardoso this is the URI Online Judge exercise itself or picked up from another site?
– Woss
What error does it give ? If it is in the URI, there are several types of errors with their respective descriptions. If it is a "Presentation Error" you will know that it is producing the correct result but formatted wrong. As for javascript in the URI it is used with Node, soon the input comes by a file and is all read as a
string
through functionreadFileSync
. The template code provided divides by lines withvar lines = input.split('\n');
. Therefore its first value would come inlines[0]
and the second inlines[1]
remembering that you have to convert to whole to do what you want.– Isac