Back to General discussions forum
I already read the tutorials on how to use this web, but I still do not understand how input() works for javascript. For instance, for
4
-1416427 -196752
6450308 -6540058
-8903353 1785381
-2847252 -21532
what does input() do to this? Does it make an array for these sets of numbers? Ex var blah = [[-141627, -196752], [6450308, -6540058]....];
Thanks in advance!
Hi! Thanks for your question!
For JavaScript here input
is just a helper method which reads a single line into string variable. I.e.
it is an analog of Python's raw_input
for example...
So in your case code may look like this:
var n = parseInt(input()); // read single value in the first line
for (var i = 0; i < n; i++) {
var s = input(); // read next line
s = s.split(' '); // split it by spaces
var a = parseInt(s[0]);
var b = parseInt(s[1]);
// ... do something with a and b
}
Of course this works only for built-in executor (i.e. when you click JavaScript
button below the source
code textarea).
This example is slightly more verbose than it is needed, but I hope it makes things more clear! As a matter
of fact since JavaScript is executed straight in your browser, you can see the source of executor (and of
input
and output
methods) in debugger of your browser (if you are curious).