-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw5.js
More file actions
57 lines (51 loc) · 1.17 KB
/
Copy pathhw5.js
File metadata and controls
57 lines (51 loc) · 1.17 KB
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
const readline = require('readline');
/* eslint no-use-before-define: 0 */
/* eslint no-plusplus: 0 */
/* eslint no-shadow: 0 */
/* eslint no-continue: 0 */
/* eslint consistent-return: 0 */
const rl = readline.createInterface({
input: process.stdin,
});
const lines = [];
rl.on('line', (line) => {
lines.push(line);
});
rl.on('close', () => {
solve(lines);
});
function solve(lines) {
const count = Number(lines[0]);
const arr = [];
for (let i = 1; i <= count; i++) {
arr.push((lines[i]).split(' '));
const [a, b, k] = arr[i - 1];
console.log(whoWin(a, b, k));
}
}
const whoWin = (numA, numB, bigOrSmall) => {
const a = numA.length;
const b = numB.length;
if (numA === numB) return 'Draw';
if (bigOrSmall === '1') {
if (a !== b) {
return a > b ? 'A' : 'B';
}
for (let i = 0; i < a; i++) {
if (numA[i] === numB[i]) {
continue;
}
return numA[i] > numB[i] ? 'A' : 'B';
}
} else if (bigOrSmall === '-1') {
if (a !== b) {
return a < b ? 'A' : 'B';
}
for (let i = 0; i < a; i++) {
if (numA[i] === numB[i]) {
continue;
}
return numA[i] < numB[i] ? 'A' : 'B';
}
}
};