-
Notifications
You must be signed in to change notification settings - Fork 0
/
MATPAN.js
58 lines (41 loc) · 1.27 KB
/
MATPAN.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Mohammed Sohail
*/
process.stdin.resume();
process.stdin.setEncoding("utf8");
const fs = require("fs");
const chunk = fs.readFileSync("/dev/stdin").toString();
function main(input) {
const inputLines = input.split("\n");
const testCases = inputLines[0];
inputLines.shift();
for (let i = 0; i < testCases; i++) {
const prices = inputLines[i];
inputLines.shift();
const string = inputLines[i];
checkMissingPangram(string, prices);
}
function checkMissingPangram(input, prices) {
const totalArray = [];
let alphabets = "abcdefghijklmnopqrstuvwxyz";
alphabets = alphabets.split("");
prices = prices.split(" ");
input = input.toLowerCase();
const missingAlphabets = [];
for (let i = 0; i < alphabets.length; i++) {
if (input.indexOf(alphabets[i]) == -1) {
missingAlphabets.push(i);
}
}
missingAlphabets.forEach(element => {
const price = prices[element];
totalArray.push(price);
});
const totalPrice = totalArray.reduce((a, b) => {
return parseInt(a) + parseInt(b);
}, 0);
console.log(totalPrice)
}
}
main(chunk);