I am doing a Kattis challenge, Booking a Room.
Basically, I get initial input - let's say 6, 4.
I have to store that input somewhere and then ask for another x inputs where x = the first value, ie. 6. Those inputs are stored elsewhere, in an array of arrays.
I tried so many different things, but either my initially stored values (6 and 4) change, or it iterates too much through the rest of the input.
I find the documentation on their website to be terrible.
https://open.kattis.com/help/javascript - for nodeJS example
My code attempts:
rl.question("initial", answer => {
let nums = answer.split(" ");
numberKittens = parseInt(nums[0]);
spareBeds = parseInt(nums[1]);
console.log("spare be", spareBeds);
console.log("num of kit", numberKittens);
rl.on(
(numberKittens,
answer => {
let first = answer.split(" ");
initialValue.push([parseInt(first[1]), parseInt(first[0])]);
console.log("initial val", initialValue);
})enter code here
);
});
The initial part works ok, but never gets to the rl.on
part and keeps asking for input forever.
Attempt two:
rl.on("line", line => {
let nums = line.split(" ");
numberKittens = parseInt(nums[0]);
spareBeds = parseInt(nums[1]);
let first = line.split(" ");
let initialValue = [];
initialValue.push([parseInt(first[1]), parseInt(first[0])]);
})
changes the numberKittens
and spareBeds
every time, messes up with the iteration.
Basically, I am trying to do something like this in Go:
fmt.Scanln(&numOfKittens, &numOfBeds)
for i := 1; i <= numOfKittens; i++ {
fmt.Scanln(&arrivalDate, &departureDate)
fmt.Println(arrivalDate, departureDate)
}