Javascript encoding

How can I submit javascript solutions for Codechef?

Can you give me an example for handling js input in a codec?

www.codechef.com

+6
source share
2 answers

Yes, this is a huge noise for every language. The best javascript implementation in Codechef is through node.js. This is for the first exercise "Life, the Universe and Everything":

process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function (chunk) { var lines = chunk.toString().split('\n'); lines.forEach(function(line) { if (line === '42') { process.exit(); } process.stdout.write(line+'\n'); }); }); 

It worked for me.

+7
source

Codechef uses the Rhino Javascript engine to evaluate solutions. Here's how to do it for JavaScript (rhino-1.7R4).

 importPackage(java.io); importPackage(java.lang); var reader = new BufferedReader( new InputStreamReader(System['in']) ); while(true) { var line = reader.readLine(); if(line == null || line == "42") { break; } else { System.out.println(line); } } 

here you can find the basic implementation in most languages

+3
source

Source: https://habr.com/ru/post/904164/


All Articles