Problem 35. macbook.js (*** continue is used revise***)

 /*Question

Input Format:
First line denotes n, the number of inputs. The next n lines contains one integer in each line.

Output Format:
One integer denoting the result, as mentioned above.

Example:
Input:

5
10
-20
30
40
50
Output:

130
Explanation:

From the given 5 integers, the result will be: 10+30+40+50 = 130
*/

let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');

function readLine() {
idx++;
return data[idx - 1].trim();
}
//======================================================================================================


let numinput = parseInt(readLine()); // 5

let functionalmac = 0;
for (i = 1; i <= numinput; i++) {

let lifespan = parseInt(readLine());
if (lifespan < 0) {
continue;
}
functionalmac += lifespan; // functionalmac = functionalmac + lifespan
}
console.log(functionalmac);

TERMINAL:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node macbook.js <input.txt 130 Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$

Comments

Popular posts from this blog

Problem 33. patter122333.js

Problem 38. diamond.js

Problem 16. chocolatebills.js