Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
kattis: why does my output contain my input?

Im trying to attempt a question on kattis Left beehind and my output is correct but somehow my input gets written with the output which im so confused about. Can anyone tell me what is the problem and how to get rid of the numbers in my output?

here is my code: (im using javascript)

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.on('line', (line) => {
    var nums = line.split(' ');
    var x = parseInt(nums[0]);
    var y = parseInt(nums[1]);
    
    if (x==0 && y==0 ) {
      return;
    }
    
    if (x+y==13) {
        console.log("Never speak again.")
    }
    else if (y>x) {
        console.log("Left Beehind.")
    }
    else if ( x > y ) {
        console.log ("To the convention.")
    }
    else{
        console.log("Undecided.")
    }
});

and this my output

17 3
To the convention.
13 14
Left Beehind.
8 5
Never speak again.
44 44
Undecided.
0 0
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your input is being written with your output because you specified process.stdout, which is your NodeJS console, as an output for the readline interface.

So, readline is successfully reading the lines, emitting the line event for each line it receives/finds, then you are performing some logic and printing some text using console.log (which in turn uses process.stdout to print to the NodeJS console). Finally, readline is streaming the lines to the same output.

Remove the output option and it should work as expected.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!