Script
Script3y ago

Script – 21-30 Jan 20

hey guys I'm not sure if I'm the one that do not understand this exercise properly but here it goes see image files From the input format, I understand that there would be multiple lines of input to pass to the function. I am not sure how that's suppose to go as the Function Description says int n: an integer. This has me really confused
6 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Script
ScriptOP3y ago
Ohhhhh So all I need to do is write code for one integer n?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Script
ScriptOP3y ago
'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});

process.stdin.on('end', function() {
inputString = inputString.split('\n');

main();
});

function readLine() {
return inputString[currentLine++];
}

/*
* Complete the 'flippingBits' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts LONG_INTEGER n as parameter.
*/

function flippingBits(n) {
return parseInt((~n >>> 0).toString(2), 2);
}

function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

const q = parseInt(readLine().trim(), 10);

for (let qItr = 0; qItr < q; qItr++) {
const n = parseInt(readLine().trim(), 10);

const result = flippingBits(n);

ws.write(result + '\n');
}

ws.end();
}
'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});

process.stdin.on('end', function() {
inputString = inputString.split('\n');

main();
});

function readLine() {
return inputString[currentLine++];
}

/*
* Complete the 'flippingBits' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts LONG_INTEGER n as parameter.
*/

function flippingBits(n) {
return parseInt((~n >>> 0).toString(2), 2);
}

function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

const q = parseInt(readLine().trim(), 10);

for (let qItr = 0; qItr < q; qItr++) {
const n = parseInt(readLine().trim(), 10);

const result = flippingBits(n);

ws.write(result + '\n');
}

ws.end();
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/933835995391074324