-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavascript.js
46 lines (46 loc) · 1.13 KB
/
Javascript.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
class Participant {
static addVote(name, vote, listP) {
let pI = listP.findIndex((e) => e.name === name);
let p = listP[pI];
if (p && p.listVote.length < p.nbVote) {
p.listVote.push(vote);
} else if (p) {
listP.splice(pI, 1);
}
}
static countVote(listP) {
let voteY = 0;
let voteN = 0;
listP.forEach((p) => {
p.listVote.forEach((v) => {
if (v === "Yes") {
voteY++;
} else if (v === "No") {
voteN++;
}
});
});
console.log(voteY + " " + voteN);
}
constructor(name, nbVote) {
this.name = name;
this.nbVote = nbVote;
this.listVote = [];
}
}
const N = parseInt(readline());
const M = parseInt(readline());
let listP = [];
for (let i = 0; i < N; i++) {
var inputs = readline().split(" ");
const personName = inputs[0];
const nbVote = parseInt(inputs[1]);
listP.push(new Participant(personName, nbVote));
}
for (let i = 0; i < M; i++) {
var inputs = readline().split(" ");
const voterName = inputs[0];
const voteValue = inputs[1];
Participant.addVote(voterName, voteValue, listP);
}
Participant.countVote(listP);