-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavascript.js
72 lines (72 loc) · 1.72 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class player {
constructor(name) {
this.name = name;
}
addShoot(shoots) {
this.shoots = shoots.split(" ");
}
calculScore() {
let points = 0;
let rounds = 0;
while (!points == 101 || !this.shoots.length == 0) {
let score = 0;
let missThisRound = 0;
let missLastShoot = false;
for (let i = 0; i < 3; i++) {
let p = this.shoots.shift();
if (p == "X") {
score -= 20;
missThisRound++;
if (missLastShoot) {
score -= 10;
}
missLastShoot = true;
} else {
let pSplit = p.split("*");
if (pSplit.length > 1) {
score += parseInt(pSplit[0]) * parseInt(pSplit[1]);
} else {
score += parseInt(p);
}
missLastShoot = false;
if (points + score > 101) {
break;
}
}
if (this.shoots.length == 0) {
break;
}
}
if (points + score <= 101) {
points += score;
}
if (missThisRound == 3) {
points = 0;
}
rounds++;
//console.log(this.name + " rounds:" + rounds + " points:" + points + " score this shoot:" +score);
}
this.totalScore = points;
return rounds;
}
}
let players = [];
const N = parseInt(readline());
for (let i = 0; i < N; i++) {
const PLAYER = readline();
players.push(new player(PLAYER));
}
let smaller = Infinity;
let smallerP = "";
for (let i = 0; i < N; i++) {
const SHOOTS = readline();
players[i].addShoot(SHOOTS);
let rounds = players[i].calculScore();
if (players[i].totalScore == 101) {
if (rounds < smaller) {
smaller = rounds;
smallerP = players[i];
}
}
}
console.log(smallerP.name);