-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1087.js
More file actions
36 lines (30 loc) · 712 Bytes
/
1087.js
File metadata and controls
36 lines (30 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 1087 top area
var input = require('fs').readFileSync('data/1087.txt', 'utf8');
var lines = input.split('\r\n');
const op = lines[0].trim();
let matriz = [];
let index = 1;
for(let i = 0; i < 12; i++){
matriz[i] = [];
for(let j = 0; j < 12; j++){
matriz[i][j] = parseFloat(lines[index++]);
}
}
let sum = 0;
let count = 0;
for(let linha = 0; linha <= 4; linha++){
for(let coluna = linha + 1; coluna < 11 - linha; coluna++){
sum += matriz[linha][coluna];
count++;
}
}
if(op == 'S'){
console.log(sum.toFixed(1));
return;
}else if(op == 'M'){
console.log((sum/count).toFixed(1));
return;
}else{
console.log('Invalid Operation');
return;
}