R
Reactiflux

Script – 21-30 Jan 20

Script – 21-30 Jan 20

SScript1/20/2022
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
UUUnknown User1/21/2022
Message Not Public
Sign In & Join Server To View
SScript1/21/2022
Ohhhhh So all I need to do is write code for one integer n?
UUUnknown User1/21/2022
Message Not Public
Sign In & Join Server To View
SScript1/21/2022
'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();
}
UUUnknown User1/22/2022
2 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

Script – 21-30 Jan 20

Join Server