-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2116번.swift
65 lines (60 loc) · 1.54 KB
/
2116번.swift
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
// 출처 : 백준 주사위 찾기
// https://www.acmicpc.net/problem/2116
// 풀이 : hogumachu
import Foundation
func solution() {
let n = Int(readLine()!)!
var table: [[Int]] = Array(repeating: [], count: n)
// 0-5, 1-3, 2-4
var top = 0
var down = 0
var nextTopIndex = 0
var nextDownIndex = 0
var result = 0
for i in 0..<n {
table[i] = readLine()!.split(separator: " ").map{Int(String($0))!}
}
func topDown(_ num: Int) -> Int {
if num == 0 {
return 5
} else if num == 1 {
return 3
} else if num == 2 {
return 4
} else if num == 3 {
return 1
} else if num == 4 {
return 2
} else {
return 0
}
}
for i in 0..<6 {
var compare = 0
top = table[0][i]
down = table[0][topDown(i)]
for j in 0..<n {
var max = 0
for k in 0..<6 {
if table[j][k] == top {
nextDownIndex = k
nextTopIndex = topDown(k)
top = table[j][nextTopIndex]
down = table[j][nextDownIndex]
break
}
}
for k in 0..<6 {
if table[j][k] != top && table[j][k] != down, table[j][k] > max {
max = table[j][k]
}
}
compare += max
}
if result < compare {
result = compare
}
}
print(result)
}
solution()