-
Notifications
You must be signed in to change notification settings - Fork 0
4-alstjr7437 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4-alstjr7437 #24
Conversation
giljihun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ์ฒด ๋ก์ง์ ๋์ผํ ๊ฒ ๊ฐ๋ค์~
/* MARK: - SOLUTION
ํ์ฌ๊น์ง ์ถ์ฒ ๋ฐ์ ํ์๊ฐ ๊ฐ์ฅ ์ ์ ํ์์ ์ฌ์ง์ ์ญ์ ํ๊ณ ,
๊ทธ ์๋ฆฌ์ ์๋กญ๊ฒ ์ถ์ฒ๋ฐ์ ํ์์ ์ฌ์ง์ ๊ฒ์.
(2๋ช
์ด์์ด๋ฉด, ๊ฐ์ฅ ๊ฒ์๋ ์ง ์ค๋๋ ์ฌ์ง ์ญ์ )
(์ด ๊ฒฝ์ฐ, ์ถ์ฒ๋ฐ์ ํ์๋ 0์ผ๋ก ์ด๊ธฐํ๋จ.)
์ข
ํ๋ณด์ ํ์ ๋ฒํธ๋ฅผ ์ฆ๊ฐํ๋ ์์๋๋ก ์ถ๋ ฅ
1. ์
๋ ฅ
2.
- ๋์
๋๋ฆฌ๋ก ์ถ์ฒํ์, ์์๋ฅผ ๊ด๋ฆฌ.
- ์ ๊ฑฐ๋ ์ถ์ฒ ํ์๊ฐ ๊ฐ์ฅ ๋ฎ์๋ OUT (๋ํ ์, ์์๊ฐ ์ ค ๋น ๋ฅธ๋)
*/
import Foundation
// MARK: - ์
๋ ฅ
guard let input = readLine(),
let N = Int(input),
(1...20).contains(N) else { exit(0) }
guard let votingCnt = Int(readLine() ?? "") else { exit(0) }
if votingCnt == 0 {
exit(0)
}
guard let votingPapers = readLine()?.split(separator: " ").compactMap({ Int($0) }) else { exit(0) }
// MARK: - ํ๋ณด ๋ฑ๋ก ๋ก์ง
var candidates: [Int: (votedCnt: Int, order: Int)] = [:]
var order = 1
votingPapers.forEach {
addCandidate($0)
}
// MARK: - ์ถ๋ ฅ
print(candidates.keys.sorted().map { String($0) }.joined(separator: " "))
// MARK: - ํจ์
// ํ๋ณด ๋ฑ๋ก ํจ์
func addCandidate(_ candidate: Int) {
if let _ = candidates[candidate] {
votingCandidate(candidate)
return
}
if candidates.count == N {
delCandidate()
}
candidates[candidate] = (1, order)
order += 1
}
// ํฌํ ๋ฐ์ ํ์ ์ฆ๊ฐ
func votingCandidate(_ candidate: Int) {
candidates[candidate]!.votedCnt += 1
}
// ํ๋ณด์ ์ ๊ฑฐ
func delCandidate() {
let minVote = candidates.values.map { $0.votedCnt }.min()
let leastVoted = candidates.filter { $0.value.votedCnt == minVote }
if let target = leastVoted.min(by: { $0.value.order < $1.value.order }) {
candidates.removeValue(forKey: target.key)
}
}์กฐ๊ฑด์ด ๋ง์ ๊ตฌํ๋ฌธ์ ๋
๊ฐ ์ ์ผ๋ก ๋ ์ฝ๋๋ฅผ ๊น๋ํ๊ฒ ์ง๋ ค๊ณ ํ๋ ๊ฒ ๊ฐ๋ค๊ณ ๋๊ผ์ต๋๋ค.
๊ทธ๋์ผ ์์ธ์ฒ๋ฆฌํ ๋ถ๋ถ๋ ๋ ๋ณด์ด๊ณ ํ๋ ๊ฒ ๊ฐ์์.
๊น๋ํ์ง ๋ชจ๋ฅด๊ฒ ์ง๋ง์..
์ด๋ฒ ๋ฌธ์ ์์ ๊ณ์ 1%์์ ์ค๋ฅ๊ฐ ๋ ์... ์๋ฌ์ก๋๋ผ ์กฐ๊ธ ์๊ฐ์ด ๊ฑธ๋ ธ๋๋ฐ
์ ๋ง ๋ณ๊ฑฐ ์๋๋ฐ, ์น๋ช
์ ์ธ ๋ฌธ์ ์์ด์!
var candidates: [Int: (votedCnt: Int, order: Int)]์ด๋ ๊ฒ ์ ์ฝ๋์ฒ๋ผ ํ๋ณด์ ๋์ ๋๋ฆฌ๋ฅผ ๊ตฌ์ฑํด์ผํ๋๋ฐ
var candidates: [String: (votedCnt: Int, order: Int)]์ ์ฝ๋์ฒ๋ผ ํ๋ณด์๋ฅผ String์ผ๋ก ์ ์ธํด๋๊ณ ... ๋๋ฒ๊น ํ๊ณ ์์์ด์..
์ด๋ ๊ฒํ๋ฉด ์ถ๋ ฅ๋ถ์์ ์๋ฅผ๋ค์ด ํ๋ณด์๊ฐ 10, 2 ์๋ค๋ฉด
๋ฌธ์ ์กฐ๊ฑด์ ๋ฐ๋ผ 2 10 ์ผ๋ก ์ถ๋ ฅ์ด ๋์ด์ผํ๋๋ฐ..
String์ ์ ๋ ฌํด๋ดค์.. 10 2 ๋ก ๋์ค๋ ๊ฒ์ด์ฃ ..
๋ฐ๋ก๋ฅผ ์ฐพ์์ ๋คํ์ด๊ณ .. ์์ผ๋ก๋ ํ์ ์ ์ข ๋ ์ ๊ฒฝ์จ์ผ๊ฒ ๋ค๊ณ ๋๊ผ์ต๋๋ค.
alstjr7437/๊ตฌํ/BOJ_1713.swift
Outdated
| @@ -0,0 +1,29 @@ | |||
| let N = Int(readLine()!)! | |||
| let totalCount = Int(readLine()!)! | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guard let votingCnt = Int(readLine() ?? "") else { exit(0) }
if votingCnt == 0 {
exit(0)
}์ ์๊พธ ์๋ฌ๋ ์
"์ค๋ง ๋ฌด์จ ํฌํ์ 0๋ช
! ์ด๋ฐ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ๋? ใ
ใ
" ํ๋ฉด์
์ฌ๊ธฐ์ ์ด๋ฐ ์กฐ๊ฑด๋ ์ถ๊ฐํ๊ณ ๊ทธ๋ฌ๋ค์ ใ
ใ
ใ
alstjr7437/๊ตฌํ/BOJ_1713.swift
Outdated
| let recommend = readLine()!.split(separator: " ").map { Int(String($0))! } | ||
|
|
||
| var result: [Int: (recommendCount: Int, time: Int)] = [:] | ||
| var currentTime = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var candidates: [Int: (votedCnt: Int, order: Int)] = [:]
var order = 1currentTime ๋ณ์๋ช ์ข๋ค์, ์ ๋ order(์์)๋ก ํ์ด๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order ์ข๋ค์ ์ ๋ time? ํ๋ ค๋ค๊ฐ ์๋ฟ์ง์์์ numberํด์คฌ๋๋ฐ, (์ ๋ ๊ธฐํธ~๋ฒ์ symbol๋ก ํด์คฌ์ต๋๋ค.) ํท๊ฐ๋ฆฌ๋๋ผ๊ตฌ์
|
๋ approveํด์ ์ฃ์ก ใ .. |
YooGyeongMo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let n = Int(readLine()!)!
let m = Int(readLine()!)!
let recommend = readLine()!.split(separator:" ").map { Int(String($0))! }
func photoFrames(frameCount n: Int, recommendationList nums: [Int]) -> [Int] {
var stack: [Int] = []
var count = Array(repeating: 0, count: 101)
for student in nums {
if stack.contains(student) {
count[student] += 1
continue
}
if stack.count == n {
// ์ถ์ฒ ์๊ฐ ๊ฐ์ฅ ์ ์ ์ฌ๋ ์ฐพ๊ธฐ
let minVote = stack.map { count[$0] }.min()!
// ๊ฐ์ฅ ๋จผ์ ๊ฑธ๋ฆฐ ํ์ ์ค ์ถ์ฒ ์ == min ์ธ ์ฌ๋ ์ ๊ฑฐ
for old in stack {
if count[old] == minVote {
count[old] = 0
if let idx = stack.firstIndex(of: old) {
stack.remove(at: idx)
}
break
}
}
}
// ์คํ์ฒ๋ผ ๋ค์ ์ถ๊ฐ
stack.append(student)
count[student] = 1
}
return stack.sorted()
}
let result = photoFrames(frameCount: n, recommendationList: recommend)
print(result.map { String($0) }.joined(separator: " "))stack ์ผ๋ก ์ง๋ณด์์ต๋๋ค.
alstjr7437/๊ตฌํ/BOJ_1713.swift
Outdated
| if result[student] != nil { | ||
| result[student]!.recommendCount += 1 | ||
| } else { | ||
| if result.count < N { | ||
| result[student] = (1, currentTime) | ||
| } else { | ||
| let removeValue = result.min { | ||
| if $0.value.recommendCount == $1.value.recommendCount { | ||
| return $0.value.time < $1.value.time | ||
| } | ||
| return $0.value.recommendCount < $1.value.recommendCount | ||
| }!.key | ||
|
|
||
| result.removeValue(forKey: removeValue) | ||
| result[student] = (1, currentTime) | ||
| } | ||
| } | ||
| currentTime += 1 | ||
| } | ||
|
|
||
| print(result.keys.sorted().map { String($0) }.joined(separator: " ")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋์
๋๋ฆฌ์ ํค์ ๋ฒจ๋ฅ ์ฌ์ฉํ์
์ ํธ์
ง๋ค์.
์ฒ์์๋
struct Candidate {
let number: Int
var votes: Int
var time: Int
}struct๋ก ์ํ๊ด๋ฆฌํ๋ ค๊ณ ํ์๋๋ฐ ์ญ์ ์๊ณ ๋ฆฌ์ฆ์์๋ ๋์ ๋๋ฆฌ๊ฐ ์ง์ธ๊ตฐ์.
์ฌ์ค ์ ๋ ๋ฌธ์ ๋ณด์๋ง์ stack๊ตฌ์กฐ๊ฐ ๋ ์ฌ๋ผ์ ๋ฐ๋ก stack๊ตฌ์กฐ๋ฅผ ์ง๋ณด์์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ ๋ณด๊ณ struct, class ์จ๋ณด๊ณ ์ถ์ด์ ์ต์ง๋ก ์จ๋ณด๋ค๊ฐ ์ข ์ค๋๊ฑธ๋ฆฌ๊ณ ๋ณต์กํด์ง ๊ฒ ๊ฐ์์. ์ ๋ง ์๊ณ ๋ฆฌ์ฆ์ dictionary๊ฐ ๋ง์๊ฑธ ํ ์ ์๊ฒ ํด์ฃผ๋ค์ ใทใท..
dictionary ๊ตฌ์กฐ๋ฅผ key value ์ฐ๋ฉด์ ์์ฒญ ๊น๋ํ๊ฒ ์ ํธ์ ๊ฒ๊ฐ์ต๋๋ค... ๋ฐฐ์๊ฐ์
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ญ๊ฐ ๊ตฌํ ๋ฌธ์ ๊ฐ ์ฌ๋ฐ๊ธฐ๋ํ๊ณ ๋์๋ ๋ง์ด๋๋ ๊ฒ ๊ฐ๋ค์..ใ ใ
๋ค๋ฅธ๋ถ๋ค ์ฝ๋๋ ๋น๊ตํด์ ๋ณด๋๋ฐ ํฌ๊ฒ ๋ค๋ฅธ์ ์ ์ ์ค๋๋ ์ฌ์ง์ ๊ตฌ๋ถํ๊ธฐ์ํ ๋ณ์๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ์ธ๋ฑ์ค๋ก ํ๋ณํด์คฌ์ด์. ๊ทผ๋ฐ ๋ค๋ฅธ๋ถ๋ค์ฒ๋ผ ๋ช ์์ ์ผ๋ก ์ฒ๋ฆฌํด์ฃผ๋๊ฒ ๊ฐ๋ ์ฑ ๋ฉด์์๋ ์ฑ๋ฅ๋ฉด์์๋ ์ข๋ค๊ณ ๋๊ปด์ง๋ค์. ๊ณ ์ํ์ จ์ด๋ค!
import Foundation
struct Candidate {
let studentNumber: Int
var recommendCount: Int
mutating func incrementRecommend() {
recommendCount += 1
}
mutating func resetRecommend() {
recommendCount = 0
}
}
var candidates: [Candidate] = []
var res: [Int] = []
// input
let N = Int(readLine()!)!
let recommandCount = Int(readLine()!)!
let recommandNumbers: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
for studentNumber in recommandNumbers {
// ์ด๋ฏธ ๊ฒ์๋ ํ์์ธ์ง ํ์ธ
if let index = candidates.firstIndex(where: { $0.studentNumber == studentNumber }) {
// ์ด๋ฏธ ๊ฒ์๋ ๊ฒฝ์ฐ ์ถ์ฒ ํ์๋ง ์ฆ๊ฐ
candidates[index].incrementRecommend()
} else {
// ์๋ก์ด ํ์์ธ ๊ฒฝ์ฐ
if candidates.count < N {
// ์ฌ์งํ์ด ๋น์ด์๋ ๊ฒฝ์ฐ
candidates.append(Candidate(studentNumber: studentNumber, recommendCount: 1))
} else {
// ์ฌ์งํ์ด ๊ฐ๋ ์ฐฌ ๊ฒฝ์ฐ
// ์ถ์ฒ ํ์๊ฐ ๊ฐ์ฅ ์ ๊ณ , ๊ฐ์ฅ ์ค๋๋ ํ๋ณด ์ฐพ๊ธฐ
let minRecommend = candidates.min { $0.recommendCount < $1.recommendCount }!.recommendCount
if let index = candidates.firstIndex(where: { $0.recommendCount == minRecommend }) {
// ๊ฐ์ฅ ์ค๋๋ ํ๋ณด ์ ๊ฑฐ
candidates.remove(at: index)
// ์๋ก์ด ํ๋ณด ์ถ๊ฐ
candidates.append(Candidate(studentNumber: studentNumber, recommendCount: 1))
}
}
}
}
res = candidates.map { $0.studentNumber }.sorted()
print(res.map { String($0) }.joined(separator: " "))
alstjr7437/๊ตฌํ/BOJ_1713.swift
Outdated
| if result[student] != nil { | ||
| result[student]!.recommendCount += 1 | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ต๊ทผ์ swiftyํ๊ฒ ์ฝ๋ ์ฐ๋ ๋ฒ์๋ํด ๊ณ ๋ฏผํ๊ณ ์์ต๋๋ค. ์ต์ ๋ nil ๊ฐ์ ์ฒดํฌํด์ฃผ๋ ์ฒด์ด๋์ด ์๋๋ฐ ์ ๋ ํจ๋์ฒ๋ผ ์ต์ํ ๋ฐฉ๋ฒ๋ง ์ฐ๊ฒ ๋๋๋ผ๊ณ ์. ์ฒด์ด๋์ ์จ์ ์๋์ฒ๋ผ ๊ฐ๊ฒฐํ๊ฒ ์ธ ์๋ ์๊ฒ ๋ค์!
์์
// ๊ธฐ์กด
if result[student] != nil {
result[student]!.recommendCount += 1
}
// ์ฒด์ด๋
result[student]?.recommendCount += 1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๊ฑฐ ์งฑ์งฑ swifty ใ ใ ํฉ๋๋ค.
alstjr7437/๊ตฌํ/BOJ_1713.swift
Outdated
| let totalCount = Int(readLine()!)! | ||
| let recommend = readLine()!.split(separator: " ").map { Int(String($0))! } | ||
|
|
||
| var result: [Int: (recommendCount: Int, time: Int)] = [:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋์ ๋๋ฆฌ๋ก ํ์ จ๊ตฐ์.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฌธ์ ๋ณด๊ณ ์ข swift์ค๋ฝ๊ฒ ํ๋ ค๊ณ ์ด๋ ๊ฒ ์ข ํน์ดํ๊ฒ ํ์ด๋ดค์ต๋๋ค.
Candidate๋ struct์ผ๋ก ๊ตฌํํด์คฌ์ด์. ์ข ๊ตฌ์กฐ๊ฐ ๋จ์ํ๊ธฐ๋๊ณ ์ข์์ ์ถ๊ฐ์ ๋๋ฐ์ ์์ด์ struct๋ก ํด์คฌ๊ณ ,
Gallery๋ class๋ก ๊ตฌํํด์คฌ๋๋ฐ, ๋ด๋ถ ์ํ lines๋ฅผ ๊ณ์ ๋ฐ๊ฟ์ค ๊ฒ ๊ฐ์์ class๋ก ๋์ต๋๋ค.
์ด ๋๊ฐ์ง๋ฅผ ์ข ๋ช
ํํ๊ฒ ๋ญ๊ฐ ์ข๋คํ๊ณ ๊ตฌ๋ถํ๋๊ฒ ์๋์ง.. ๊ถ๊ธํ๋ค์.. ๋ง๊ณ ๋ ์ด์ง ์๊ธฐํ์๋๋ struct๋ก ํ๋๊ฑธ ์ข ์งํฅํ๋ผ๊ณ ํ์๊ธด ํ์
จ๋๋ฐ, ์ข ๋ ์์๋ด์ผํ ๊ฒ ๊ฐ์ต๋๋ค...
import Foundation
struct Candidate: Equatable {
var symbol: Int
var like: Int = 1
let idx: Int
mutating func updateLike() {
like += 1
}
// ๋ถ๋ฆฐ์์
// mutating func updateIdx(_ idx: Int) {
// self.idx = idx
// }
}
class Gallery {
var limit: Int
var lines = [Candidate]()
init(_ limit: Int) {
self.limit = limit
self.lines = []
}
// ํด์ถ์ ๋
func out() {
let minLike = lines.min(by: {
if $0.like == $1.like {
return $0.idx < $1.idx
}
return $0.like < $1.like
})!
lines.remove(at: lines.firstIndex(where: { $0.symbol == minLike.symbol })!)
}
func append(_ candidate: Candidate) {
if let alreadyIdx = lines.firstIndex(where: { $0.symbol == candidate.symbol }) {
lines[alreadyIdx].updateLike()
}
else {
// ๊ฝ ์ฐจ๋ฉด ํด์ถ
if lines.count == limit {
out()
}
// ์์ง ๊ฝ ์ฐจ์ง ์์๋ค๋ฉด ? ๊ฑ ์ถ๊ฐ
lines.append(candidate)
}
}
func answer() {
lines.sort { $0.symbol < $1.symbol }
// print(lines)
lines.map { $0.symbol }.forEach {
print($0, terminator: " ")
}
}
}
func solution(_ n: Int, _ arr: [Int]) {
let gallery = Gallery(n)
for (idx, item) in arr.enumerated() {
gallery.append(Candidate(symbol: item, idx: idx))
}
// gallery.out()
gallery.answer()
}๊ณ์ ์ ๋ต 20%์์ ํ๋ ธ์ต๋๋ค๊ฐ ๋ฌดํ์ผ๋ก ๋ฑ์ฅ
append ํจ์์์ ๋ฌธ์ ๊ฐ ์์์. ๊ทธ๋ฅ ๊ฝ ์์ฐผ์ผ๋ฉด ์๊ฐ์์ด append๋ฅผ ํด์ฃผ๊ณ ์๋ค๋ณด๋, ์ค๋ณต์ด ๋ง๋ค์ด๊ฐ !!!
๊ธฐ์กด append
func append(_ candidate: candidate) {
// ์์ง ๊ฝ ์ฐจ์ง ์์๋ค๋ฉด ? ๊ฑ ์ถ๊ฐ
if lines.count < limit {
lines.append(candidate)
} else {
// ๋ง์ฝ์ ์ด๋ฏธ ์๋ ์ ๋ผ๋ฉด !
if let alreadyIdx = lines.firstIndex(where: { $0.symbol == candidate.symbol }) {
lines[alreadyIdx].updateLike()
} else {
// ์ด๋ฏธ ์๋ ์ ๊ฐ ์์ผ๋ฉด ํ๋ณด ๊ต์ฒด
out()
lines.append(candidate)
}
}
}๋ณ๊ฒฝํ append
func append(_ candidate: Candidate) {
if let alreadyIdx = lines.firstIndex(where: { $0.symbol == candidate.symbol }) {
lines[alreadyIdx].updateLike()
}
else {
// ๊ฝ ์ฐจ๋ฉด ํด์ถ
if lines.count == limit {
out()
}
// ์์ง ๊ฝ ์ฐจ์ง ์์๋ค๋ฉด ? ๊ฑ ์ถ๊ฐ
lines.append(candidate)
}
}ํ์ด
- ์๋ ์ต๊ทผ์ ์ถ์ฒ๋ชป๋ฐ์์ ๊ฐ ํ๋ฝํ๋์ง์๊ณ ,
updateIdx๋ฅผ ์ฌ์ฉํ๋ค๊ฐ ํ๊ธฐํ์ต๋๋ค. - ํ๋ณด๋ค์ด ๋ชจ์ฌ์๋ ๊ณต๊ฐ์
Gallery๋ก class๋ฅผ ๋๊ณ , ์ฌ๊ธฐ์์ ํ๋ณด๋ค์ ์ถ๊ฐํ๊ณ .. ํด์ถํ๋ ๋ฑ ๊ด๋ฆฌ๋ฅผ ํด์คฌ์ต๋๋ค. - ์ฝ๋ ๊ตฌ์กฐ์์ฒด๋ class์ struct๋ง ๋ณด์๋ฉด ์ฌ์ค ๊ทธ๋ฅ
appendํ๊ฐ๋ผ์ ์ดํดํ๊ธฐ ์ฌ์ฐ์ด ๊ฒ ๊ฐ์์
append
- ์ด๋ฏธ Gallery์ lines์ ์๋ ํ๋ณด๋ฉด ์ข์์ ์ถ๊ฐ
- ๊ฝ ์ฐจ๋ฉด ํด์ถ
- ๊ฝ ์ฐจ์ง ์์๋ค๋ฉด ๊ฑ ์ถ๊ฐ
out
- ์ข์์ ์ ๋น๊ต
- ๊ทธ ๋ค์์ผ๋ก idx ๋น๊ต (๊ฒ์๋ ์๊ฐ ์)
answer
- ๋ฐฑ์ค์์ ์ํ๋ ํํ ์ ๋ต ์ถ๋ ฅ
๋น์ฅ ์๊ฐ๋๋ ๊ฐ์ ์
์๋ง ์ง๊ธ idx๋ก ํด์ฃผ๊ณ ์๋๊ฑฐ๋ฅผ idx ์
๋ ฅ๋ฐ์ง๋ง๊ณ , Gallery์์์ ํ๋ํ๋ ๋ณ์๋ก appendํด์ค๋๋ง๋ค +=1 ํด์ฃผ๋ฉด ๋ ๊ฐ์์ฑ์๊ฒ ๊ตฌ์ฑ์ด ๋ ๊ฒ ๊ฐ๋ค์
|
์คํธ ํ ๋ฆฌ๋ทฐ๋ฅผ ์์ฒญ ์์ธํ๊ฒ ๊ทธ๋ฆฌ๊ณ Swift์ค๋ฝ๊ฒ ํธ์ จ๋ค์ ์๋ดค์ต๋๋ค!! |
๐ ๋ฌธ์ ๋งํฌ
ํ๋ณด ์ถ์ฒํ๊ธฐ
๋ค์
๊ทธ ๊ธฐ๊ฐ์ด๋ ๋ฌธ์ ๋ฅผ ๋ค๊ณ ์์ต๋๋ค!(์ ์น ํฌ์คํฐ๋ ๋ ผ๋์ด ์๊ธธ ๊ฒ ๊ฐ์์)โ๏ธ ์์๋ ์๊ฐ
25๋ถ
โจ ์๋ ์ฝ๋
๋ฌธ์ ๋ ๋จ์ ๊ตฌํ์ด์์ต๋๋ค!!
์ 4๊ฐ์ ๋ก์ง๋ง ์๊ฐํ๋ฉด ๋์ต๋๋ค.
๊ทธ๋์ ๋จ์ํ๊ฒ ์ ๋ก์ง ์์๋๋ก ๋ฃ์ด์คฌ์ต๋๋ค!
recommend ๋ชจ๋ ๋ฐ๋ณต๋ฌธ ๋๊ธฐ
์ด๋ฏธ result์ ์กด์ฌ?
์ ๋ก์ง๋๋ก ํ๋ฌ๊ฐ์ต๋๋ค!!
์๋ง ์๋ ์ ๋ต ์ฝ๋๋ฅผ ๋ณด์๋ฉด ์ดํด๊ฐ ํธํ์ค๊บผ์์!(์ฃผ์๋ ๋ฌ์๋จ์ต๋๋ค!)
์ ๋ต ์ฝ๋
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
๋์ ๋๋ฆฌ ์์ set์ ๋ฃ์ด์ ๋ณ์๋ช ์ ์ง์ด์ ์์ฑํ๋ ๋ฌธ์ ๋ฅผ ํ๋ ํ์คํ ๊ฐ๋ ์ฑ๋ ์ข๊ณ ์ดํด๋ ํธํ๋๋ผ๊ตฌ์!!
์ ๋ ์ฒ์์๋ ๊ทธ๋ฅ
var result: [Int: (Int, Int)] = [:]์ผ๋ก ํ์๋ค๊ฐ ๋ฆฌํฉํ ๋ง์ ํด์คฌ์ต๋๋ค!์ด์
์ดํ