-
Notifications
You must be signed in to change notification settings - Fork 0
3-MuchanKim #14
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
3-MuchanKim #14
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,28 @@ | ||
| import Foundation | ||
|
|
||
| func solution(_ n: Int, _ tips: [Int]) -> Int { | ||
| let sortedTips = tips.sorted(by: >) | ||
|
|
||
| var totalTip = 0 | ||
| for i in 0..<sortedTips.count { | ||
| let actualTip = sortedTips[i] - i | ||
| if actualTip > 0 { | ||
| totalTip += actualTip | ||
| } | ||
|
Comment on lines
+7
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. μ¬μ€μ λμΌν κ² κ°μ΅λλ€! for (idx, value) in sortedArr.enumerated() {
answer += value - idx > 0 ? value - idx : 0
}
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. @bishoe01 finnμ€ μ λ enumerated() μΌμ΄μ© !!! νμ€λ Hoxy~~~ python??? λλ? μΌ λλ γ γ
MuchanKim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return totalTip | ||
| } | ||
|
Comment on lines
+3
to
+15
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. μ΄κ² 그리λλ κ°μ΄ μ κ·Όνλλ° μ λ enumrated() ν¨μλ‘ indexμ valueλ₯Ό ν¨κ» λ±μ΄μ£Όλ ν¨μλ‘ μμ±νμ΅λλ€. ! import Foundation
// μλ μ£Όλ €κ³ νλλ -(λ°μ λ±μ - 1) λ§νΌ νμ κ°νΈμκ² μ€λ€.
// μμλ 0
// μ μΌ λ§μ΄ λ°λ λ²μ κ°μ₯ ν°μκ° μμ μ€κ³ 0λ±μΌλ‘ μ€λλ²μ΄λ€.
let n = Int(readLine()!)!
var numbers: [Int] = []
for _ in 0..<n {
let num = Int(readLine()!)!
numbers.append(num)
}
numbers.sort(by:>) // λ΄λ¦Όμ°¨μ
var maxTip = 0
for (idx,tip) in numbers.enumerated() {
let takeTip = tip - idx
guard takeTip > 0 else { break} // λ€μκΊΌ λ€ λνμμμ
maxTip += takeTip
}
print(maxTip)
μ¬κΈ°μ μ λ 2κ°μ§λ₯Ό κΉ¨λ«λλ°μ.
μ¬μ€ 무 μ½λλ₯Ό 보λ γ γ enumrated()λ λ무 λΉ‘λκ° λ§Ήν€λ‘ 보λλ°λ‘ ꡬνμ΄μ§ μμλμΆμ΄μ. ++ μ μ κ°μΈμ μΈ μκ°μ λλ€. λ¬΄κ° μ½ν κ²½νμ΄ μμΌμ λ¬λλΆμκ² μ¬μ€λ³΄μ ¨λ€νλλ°, μ μ μκ°μ μ‘°κΈ λ€λ¦ λλ€. κΈ°μΆλ¬Έμ λ§ λ³΄μλ, API μμ± λ¬Έμ κ° λ§κ³ μ΄λ²μ μ½ν νΌ λ¬Έμ 2λ²μ μμ λλκ³ APIμμ±λ¬Έμ ( μΉ΄μΉ΄μ€, λ€μ΄λ²μ) -> μ΄ λ§μ μ¦, ν¨μλ³λ‘ λλ μ νλΌλ―Έν°λ₯Ό μ μ΄μ©νλλ. (νλΌλ―Έν° ν¨μ νλ μ 골격 μμ κ°λ₯νλλ ? -> μΌμ±μμ λΆκ°λ₯νμ΅λλ€. ) κ·Έλμ ν¨μλ₯Ό λ§λ€κ³ λ‘μ§λ³λ‘ μ λλλκ²μ νμνλ€ μκ°ν©λλ€. κ·Έλ¬λ λ§μ½ λ¬Έμ μ λν μ΄ν΄λλ μλλ° λλκ³ μλκ²μ λΆλͺ λΉν¨μ¨μ μΈκ²μ λ§μ΅λλ€. κ·Έλ¬λ μ°μ΅ν λ μ‘°μ°¨ κ·Έλ₯ 맨λ μ μ€μ€ μ λκ²μ μμ’μ μ΅κ΄μΈκ±° κ°μ΅λλ€. μ λν ν¨μλ‘ μ μ§ μκ³ μ΄λ²μ κ·Έλ₯ μ μΆνμμΌλ, νλ‘κ·Έλλ¨Έμ€ + ν ν¬ κΈ°μ + μ¬κΈ°μ μ‘°μ°¨λ λ€ API μꡬ 쑰건μ΄λ©° μ κ° μ³€μλ μΌμ± μ½ν μ‘°μ°¨λ μ λ§ λ³΅μ‘ν ꡬνμ΄κ³ λ°λ³΅μ μΈ create , delete , updateλ₯Ό μκ³ λ¦¬μ¦μ μ§μμΌλ‘ μΌλ§λ μ΅μ νμν€λλμμ΅λλ€.(1λ² λ¬Έμ κ° λΉ‘κ΅¬νμ΄μ§λ§ κ²°κ΅ μκ³ λ³΄λ©΄ create, delete, update μμ΅λλ€. ) κ·Έλμ μΌμ±μμλ 2λ¬Έμ λ₯Ό 4μκ°μ μ€λ€κ³ μκ°ν©λλ€. λ°λ³΅μ μΈ μ°μ°μ μ¦, ν¨μλ₯Ό μ κ·Ή νμ©νλΌλΌλ λ»μΌλ‘ ν΄μλ©λλ€. λν, μ κ° μ³€μλ μλ§ μ½ν μμλ μ 2λ¬Έμ μμλ λκ² μ½κ² νλ Έμ§λ§ λ·λ¬Έμ λ€μ ν¨μλ₯Ό ꡬλΆμ§κ±°λ λ΄κ° μ΄ν΄νλ°κ° μ ννκ² λ‘μ§λ³λ‘ λΆλ¦¬μμΌλμ§ μκ³ μ€μ€νΌλ€λ©΄ μ λ νλ¦¬μ§ μμ λ¬Έμ λ€μ΄μμ΅λλ€. -> SQL λ¬Έμ λν CTE κ°μ ν μ΄λΈ ννμΌλ‘ νμμλλ μ΄λ»κ²λ³΄λ©΄ ν¨μμ²λΌ λ΄κ° μκ°ν κ²λ€μ λͺ¨λνλ₯Ό μ μν€λλμμ΅λλ€. μ λ 무λ κΈΈ μ½λλ₯Ό 보면μ λ°μ± λ§μ΄ ν©λλ€. κΈΈμ μ£Όμμ μ λ§ κΌΌκΌΌν μμ±νκ³ κ·Έκ²λ MARKλ₯Ό νμ©νμ¬, + μ€μνν°νκ² guardλ¬Έμ νμ©νλ€λκ² μ§κΈμ λκ² μΆκ°μ μΈ κΈ°νλΉμ©μ΄ λ€μ΄κ°μ§λ§ μ΄νμλ μ λ§ λΉμ λ°ν κ²μ λλ€. λν λ¬΄κ° μμ±νλ ν¨μλ³λ‘ λ‘μ§λΆλ¦¬, μ΄κ² μ§κΈ λΉμ₯ μ½ν μ μ°μμ΄λΌλ©΄ λ³λ‘λ€ ! λΌκ³ ν μ μκ² μ΅λλ€λ§...( μ¬μ€ μ λ³λ‘μΈμ§ μ λ μ λͺ¨λ₯΄κ² μ΅λλ€... γ ... ) μ λ μ°μ΅λ μ λ κ² ν΄λμΌλ©΄ μΆνμ λ¬Έμ λ₯Ό 보μμλ μ΄λ»κ² λΆλ¦¬μν¬μ§ λν λλ²κΉ μμ μκ°μ μ λ§ λ¨μΆμν¬ μ μλ€λ μ μμ μ λ 무쑰건 μ κ·Ή μ°¬μ±μ λλ€. -> μ± μ νμ μ½ν λ μμ§λ§ κ³Όμ μ νλ μκΈ°μ.. λ¬Όλ‘ μ λ§μμ νμ λ¬λ λΆμ λ§μλ μ΄ν΄κ° κ°μ§λ§ μ λ μ λ§μ κ²½κ³νκ³ μ½ν λ₯Ό μ€λΉνλ μ μ₯μμλ μ‘°μ¬μ€λ μ견μ λ΄λ΄ λλ€.
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. λ§μ½ λ¬λλ€λΌλ¦¬μ λ§μ΄ λκ° μ‘°κΈ ν·κ°λ¦¬μκ³ λ°μλ€μ΄κΈ°μ νλμ λ€κ³ νλ¨λμλ©΄ μ λ νλ‘κ·Έλλ¨Έμ€μμ μΉ΄μΉ΄μ€ κΈ°μΆ, μΌμ± κΈ°μΆ, ν κΈ°μ κΈ°μΆ λ¬Έμ λ€μ νμ΄λ³΄μκ³ λμ νλ¨νμλ©΄ μ’μλ―ν©λλ€. λΆλͺ μΆμ λν₯κ³Ό νΈλ λλ λ³νμ§λ§ νμ¬ νΈλ λλ κ·Έλ°κ±°κ°μ΅λλ€.
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. μ’μ κΈ κ°μ¬ν©λλ€. κ°λ μ±κ³Ό ꡬ쑰 vs μ€μ μλκ° λ± κ³ λ―Όμ μ£Όμ λΌκ³ μκ°μ΄ λ€μμ΄μ.. "μ΄κ±Έ κ΅³μ΄ ν¨μλ‘ λΊκΉ?" νμ§λ§ μ λ λ¨μνκ² "μ΄μ°¨νΌ λλ²κΉ ν΄μΌλΌ" λΌλ μκ°μ κ°μ§κ³ μμ΅λλ€. μκ°ν΄λ³΄λ©΄, line1λΆν° print()κΉμ§ μμ μν΄λ³Έ μ½λλ μλ κ² κ°κ΅¬μ.. κ·Έλ¦¬κ³ μ°λ¦¬κ° μνκ³ μ νλ κ²μ λ²κ·Έ ZERO μ½λλ₯Ό μ§λκ² μλ, κ·Έλ¦¬κ³ νμ¬μμλ κ°λ°λ§ μνλκ² μλ λ²κ·Έλ₯Ό μ νμ
νκ³ μ‘λ μ¬λμ μνμ§ μμκΉ μΆλ€μ ~!!
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.
Collaborator
Author
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. ν¬... μ§μ¬μ΄λ¦° μ‘°μΈ κ°μ¬ν©λλ€ λ€λ€..! μΌμ΄μ€μν¬νΈ μ§λ루λ€μ. μ΄λ° TMIμμ£Ό μ¬λ €μΌκ² μ΄μ. μ’κ² λ΄μ£Όμλ λ€νμ λλ€! λ§νμ λλ‘ λͺ¨λννλ κ²μ΄ μ λ μ’λ€κ³ μκ°νκ³ μμ΄μ. νμ§λ§ λ¬Έμ λ₯Ό νμ μμ΄μ λΆνμν μμλ€. ν¨μλͺ μ κ³ λ―Όνλ€λμ§, μμ κΈ°λ₯μ΄λΌλ λ€ ν¨μλ‘ μͺΌκ° λ€λμ§. μ΄λ° λΆλΆλ€μ λ€μνλ² κ³ λ―Όν΄λ΄μΌν κ² κ°κΈ΄ν΄μ. μ€μ λ‘ λ¬Έμ ν λ λ€μ΄λ°μ κ³ λ―Όνλ νΈμ΄κΈ΄ν©λλ€.. λ€ λͺΈμΌλ‘ 체λνλ κ³Όμ μ΄λΌ μκ°νκ³ μ΄λ κ²λ ν΄λ³΄κ³ μ λ κ²λ ν΄λ³΄λ €κ³ μ! κ·Έλ κ² μ λ§μ κΈ°μ€μ λ§λ€μ΄κ°λ©΄ λλ κ² μλκ² μ΅λκΉ? λͺ¨λ κ°μ¬ν΄μ!
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. @MuchanKim 무!! μμ !! μ΄μΏ μ£ !
Comment on lines
+3
to
+15
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. solution! 무 λ¬Έμ λ₯Ό νλλ©΄ // ν κ³μ° ν¨μ
func calculateTip(_ tip: Int, _ order: Int) -> Int {
var realTip = tip - (order - 1)
realTip = realTip < 0 ? 0 : realTip
return realTip
} |
||
|
|
||
| // μλ μ μ λ ₯ | ||
| let n = Int(readLine()!)! | ||
|
|
||
| // κ° μλμ ν μ λ ₯ | ||
| var tips: [Int] = [] | ||
| for _ in 0..<n { | ||
| let tip = Int(readLine()!)! | ||
| tips.append(tip) | ||
| } | ||
|
Comment on lines
+17
to
+25
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. μ λ ₯λ°λ λΆλΆ κ°μ Έλ€ μΌμ΅λλ π
Collaborator
Author
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. ν μ λ ₯ λ°λ λΆλΆ κ°μ Έλ€ μ°λκ±° λ³΄κ³ μ λ κ·Έλ¬κ³ μμ΄μ γ γ γ |
||
|
|
||
| let res = solution(n, tips) | ||
| print(res) | ||

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.
μ²μμ μ λ κ·Έλ₯
sortedνλ€κ° λ¬κΈμμ΄ νλ €μ κΈνκ²reversedλ£μ΄μ£Όκ³ λ§μ·λλ°, byμ°λκ±Έ κΉλ°νλ€μ! π μμ§μκ² μ΅λλ€.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.
무μ°λ μμ