How to read to the end of the file with Javascript - Uri Online Judge

Asked

Viewed 1,093 times

0

In javascript I am using the Uri online Judge platform, however, I found nothing about reading until the EOF (End of File) in javascript.

Could someone tell me how to read up to the EOF with javascript?

  • The example code they put on the platform (in Node) already brings all the lines, and you can go reading line by line doing while(lines.length > 0){ let line = lines.shift(); or even with for (let line of lines){. Now I tell you that some of the exercises there have input problems that cause the code to fail, even without being wrong.

1 answer

2


When you select Javascript, the snippet will already appear for you:

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

/**
 * Escreva a sua solução aqui
 * Code your solution here
 * Escriba su solución aquí
 */

That reads all the contents of the entry, down to the EOF and divide by lines. You don’t have to worry about that.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.