-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmentoring.js
More file actions
56 lines (51 loc) ยท 1.75 KB
/
mentoring.js
File metadata and controls
56 lines (51 loc) ยท 1.75 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
/**
* @desc problem : ๋ฉํ ๋ง
* @desc site : Olympiad
* @desc level: 4
* @desc solution : 4์ฐจ์ ๋ฐฐ์ด (๋ชจ๋ ๊ฒฝ์ฐ์ ์ ํ์)
*/
/**
* solution
* @param {array} test : ์ํ๊ฒฐ๊ณผ
*/
function solution(test) {
let answer = 0;
const testCase = [];
//๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํ๊ธฐ ์ํ ํ
์คํธ์ผ์ด์ค 2์ฐจ์ ๋ฐฐ์ด ์์ฑ
test.forEach(function (item) {
this.push(item.toString().split(''));
}, testCase);
const person = testCase[0].length;
//๋ฉํ ์ ๋ฉํฐ ๊ฒฝ์ฐ์ ์
for (let mento = 1; mento <= person; mento++) {
for (let mentee = 1; mentee <= person; mentee++) {
let count = 0;
//์ํ์ ๊ฒฝ์ฐ์ ์
for (let x = 0; x < test.length; x++) {
let mentoRank = 0;
let menteeRank = 0;
for (let y = 0; y < person; y++) {
const target = testCase[x][y];
//์ํํ๋ฉด์ ๋ฉํ ๋, ๋ฉํฐ ํ๋ณด์ ์ฐจ๋ก์ด๋ฉด ๋ฑ์ ์ ์ฅ
if (target == mento) {
mentoRank = y;
}
if (target == mentee) {
menteeRank = y;
}
}
//๋ฉํฐ ๋ฑ์๊ฐ ๋ฉํ ๋ฑ์๋ณด๋ค ๋ฎ์๊ฒฝ์ฐ (๋ฐฐ์ด์์์ ๋ค์ ์์นํ ๋๋ก ๊ฐ์ฃผ)
if (mentoRank < menteeRank) {
count++;
}
}
//๊ฐ ๋ฉํ , ๋ฉํฐ์ ์ํ ๊ฒฝ์ฐ์ ์์์ ๋ชจ๋ ์ํ ๊ฐฏ์๋งํผ ์กฐ๊ฑด ๋ง์์ผ ์ธ์ ํ๋ค.
if (count === test.length) {
answer++;
}
}
}
return answer;
}
const answer = solution([3412, 4321, 3142]);
console.log(answer); //3