-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| let N = Int(readLine()!)! | ||
| let totalCount = Int(readLine()!)! | ||
| let recommend = readLine()!.split(separator: " ").map { Int(String($0))! } | ||
|
|
||
| var result: [Int: (recommendCount: Int, time: Int)] = [:] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋์ ๋๋ฆฌ๋ก ํ์ จ๊ตฐ์. |
||
| var currentTime = 0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. var candidates: [Int: (votedCnt: Int, order: Int)] = [:]
var order = 1currentTime ๋ณ์๋ช ์ข๋ค์, ์ ๋ order(์์)๋ก ํ์ด๋ค.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| for student in recommend { | ||
| if result[student] != nil { | ||
| result[student]!.recommendCount += 1 | ||
| } else { | ||
|
Comment on lines
+9
to
+11
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 += 1
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด๊ฑฐ ์งฑ์งฑ swifty ใ ใ ํฉ๋๋ค. |
||
| 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: " ")) | ||
|
Comment on lines
+9
to
+29
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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๊ตฌ์กฐ๋ฅผ ์ง๋ณด์์ต๋๋ค.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ ๋ ๋ณด๊ณ struct, class ์จ๋ณด๊ณ ์ถ์ด์ ์ต์ง๋ก ์จ๋ณด๋ค๊ฐ ์ข ์ค๋๊ฑธ๋ฆฌ๊ณ ๋ณต์กํด์ง ๊ฒ ๊ฐ์์. ์ ๋ง ์๊ณ ๋ฆฌ์ฆ์ dictionary๊ฐ ๋ง์๊ฑธ ํ ์ ์๊ฒ ํด์ฃผ๋ค์ ใทใท.. |
||
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.
์ ์๊พธ ์๋ฌ๋ ์
"์ค๋ง ๋ฌด์จ ํฌํ์ 0๋ช ! ์ด๋ฐ ์ฒ๋ฆฌ๋ฅผ ํด์ผํ๋? ใ ใ " ํ๋ฉด์
์ฌ๊ธฐ์ ์ด๋ฐ ์กฐ๊ฑด๋ ์ถ๊ฐํ๊ณ ๊ทธ๋ฌ๋ค์ ใ ใ ใ