-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (60 loc) · 1.95 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'acmTeam' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts STRING_ARRAY topic as parameter.
*/
function acmTeam(topic) {
// Write your code here
let arrayTopics = topic;
let maxTopics = 0;
let maxTeams = 0;
for(let i = 0; i < arrayTopics.length; i++) {
for(let j = i + 1; j < arrayTopics.length; j++) {
let knowsTopic = 0;
for(let k = 0; k < arrayTopics[i].length; k++) {
if(arrayTopics[i][k] === '1' || arrayTopics[j][k] === '1') {
knowsTopic++;
}
}
if(knowsTopic > maxTopics) {
maxTopics = knowsTopic;
maxTeams = 1;
}else if(knowsTopic === maxTopics) {
maxTeams++;
}
}
}
let result = [maxTopics, maxTeams];
return result;
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const firstMultipleInput = readLine().replace(/\s+$/g, '').split(' ');
const n = parseInt(firstMultipleInput[0], 10);
const m = parseInt(firstMultipleInput[1], 10);
let topic = [];
for (let i = 0; i < n; i++) {
const topicItem = readLine();
topic.push(topicItem);
}
const result = acmTeam(topic);
ws.write(result.join('\n') + '\n');
ws.end();
}