how can I submit solutions in Javascript for Codechef questions?
can you give me an example to handle js input at codechef?
www.codechef.com
Yes this is for each language a huge hazzle. The best javascript implementation in Codechef is via 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');
});
});
For me this worked.
Codechef uses Rhino Javascript engine to judge solutions. This is how it can be done 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 a basic implementation in most of the languages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With