Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sep037/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
| 1์ฐจ์‹œ | 2025.04.05 | ๊ตฌํ˜„ | [์ˆซ์ž ์ •์‚ฌ๊ฐํ˜•](https://www.acmicpc.net/problem/1051)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/6|
| 2์ฐจ์‹œ | 2025.04.10 | DFS | [ํŠธ๋ฆฌ์˜ ๋ถ€๋ชจ ์ฐพ๊ธฐ](https://www.acmicpc.net/problem/11725)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/12|
| 3์ฐจ์‹œ | 2025.04.38 | ์ •๋ ฌ | [์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด](https://www.acmicpc.net/problem/11656)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/13|
---
25 changes: 25 additions & 0 deletions sep037/์ •๋ ฌ/BOJ_11656.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// main.swift
// 11656
//
// Created by Seungeun Park on 4/28/25.
//

import Foundation

let N = readLine()!
let num = N.count
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swift์˜ String.index๋ฅผ ์ž˜ ํ™œ์šฉํ•œ ๋ฌธ์ œ๊ณ  ํ’€์ด๋„ ๊น”๋”ํ•˜๋„ค์—ด ~. ~

์‚ฌ์†Œํ•œ ๋ถ€๋ถ„์ธ๋ฐ, ์ €๋Š”

let num = N.count 

๋ถ€๋ถ„์ด ์กฐ๊ธˆ์€ ์ถ”์ƒ์ ์ด์ง€ ์•Š๋‚˜ ์‹ถ์Šต๋‹ˆ๋‹ค!
length, stringLength ์ด๋Ÿฐ๊ฑด ์–ด๋–จ๊นŒ์š”??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var array: [String] = []

๋„ ๊ฒฐ๊ตญ ๋ฆฌํ„ด์šฉ์ด๋ผ๋ฉด result๋‚˜ answer๋„ ๊ดœ์ฐฎ์•„๋ณด์ด๊ตฌ์š”!
ํ˜น์€, ๊ตฌ์กฐ๋ฅผ ์„ค๋ช…ํ•œ๋‹ค๋ฉด suffixes?์ด๋Ÿฐ๊ฑฐ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ญ์•ผ ์ด ๋ฉ‹์Ÿ์ด๋Š”

Copy link
Collaborator

@YooGyeongMo YooGyeongMo May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giljihun dropfirst(), ropfirst(),opfirst(),pfirst(),first(),irst(),rst(),st(),t()

var array : [String] = []

for i in 0 ..< num {
let startIndex = N.index(N.startIndex, offsetBy: i)
let suffix = N[startIndex...]
array.append(String(suffix))
Comment on lines +15 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋Š” removeFirst() ์‚ฌ์šฉํ•ด์คฌ๋Š”๋ฐ, String.index์‚ฌ์šฉํ•ด์„œ sliceํ•˜์‹ ๊ฒŒ ๋” swift๋‹ค์šด๋А๋‚Œ์ด๋„ค์š”..!
์ด๊ฑฐ๋กœ ์„ฑ๋Šฅ๋น„๊ต๋ฅผ ํ•œ๋ฒˆํ•ด๋ดค๋Š”๋ฐ ์•„๋ž˜ ๋” ์ž์„ธํžˆ ๋‚จ๊ฒจ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค !

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bishoe01 ํ—ค์ดํ—ค์ด finn~ ์—ญ์‹œ ์ง์ด๋„ค์˜ˆ ๋ฐ‘์— ์ฝ”๋“œ ๋ณด๊ณ ์™”๋Š”๋ฐ์˜ˆ ์ œ๊ฐ€ ๋ฌธ์ž์—ด ํ’€๋•Œ๋Š” type(of:) ๋‹ค ์ฐ์–ด๋ณด๋Š” ํŽธ์ž…๋‹ˆ๋‹ค์š” !!

๊ทธ๋ž˜์„œ ๋ฌธ์ž์—ด ์Šฌ๋ผ์ด์‹ฑ์œผ๋กœ ์šฐ์งธ ์•ˆ๋ ๊นŒ ?? ํ•ด์„œ ๋ณด๋‹ˆ ์—ญ์‹œ๋‚˜ str[startIndex...]์œผ๋กœ ๊ฐ€๋Šฅํ•˜๋˜๋ฐ ์ด๊ฒŒ Substring์ด๋”๋ผ๊ตฌ์š”

๊ทธ๋ž˜์„œ ์ฒซ ๋ฐฐ์—ด์„ [Substring] ์œผ๋กœ ํ•ด์ฃผ๊ณ  O(N)์œผ๋กœ ๋˜๊ฒŒ ํ•œ๋ฒˆ ํ•ด๋ดค๋Š”๋ฐ ํ†ต๊ณผ ๋˜์—ˆ์œผ์˜ˆ

import Foundation

let str = readLine()!

var strArray: [Substring] = []

for i in 0..<str.count {
    let startIndex = str.index(str.startIndex, offsetBy: i)
    strArray.append(str[startIndex...])
//    print(type(of:str[startIndex...]))
}

for item in strArray.sorted(){
    print(item)
}

๋น„์Šทํ•˜๋ ค๋‚˜์š” ? ๋ฒค์น˜๋งˆํ‚น ๊ฐ€๋Šฅํ•˜์‹ ๊ฐ€์˜ˆ ?

Copy link
Member

@giljihun giljihun May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋Š” dropFirst() ๋ฅผ ์‚ฌ์šฉํ•ด๋ดค๋Š”๋ฐ์š”.

dropFirst()๋Š” ์•ž ๋ฌธ์ž๋ฅผ ๊ฑด๋„ˆ๋›ด Substring์„ ๋ฆฌํ„ดํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ฆ‰์‹œ ๋ณต์‚ฌ๊ฐ€ ์ผ์–ด๋‚˜์ง„ ์•Š์ง€๋งŒ,
๊ทธ๊ฑธ ๋‹ค์‹œ String()์œผ๋กœ ๋ณ€ํ™˜ํ•ด์„œ ์ €์žฅํ•˜๊ฒŒ ๋˜๋ฉด, ๊ทธ ์‹œ์ ์—์„œ๋งŒ ๋ณต์‚ฌ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ ์ฒ˜์Œ์—” ์ด ๋ฐฉ์‹์ด ์ตœ์„ ์ด๊ฒ ๊ตฌ๋‚˜? ์‹ถ์—ˆ๋Š”๋ฐ.

๋ง์”€ํ•˜์‹  removeFirst() ๋ฐฉ์‹์ด COW ์กฐ๊ฑด์—์„œ ํฌ์ธํ„ฐ๋งŒ ์ด๋™ํ•˜๋Š” ์‹์œผ๋กœ ์ฒ˜๋ฆฌ๋ผ์„œ
์‹ค์ œ๋กœ๋Š” ๋” ๋น ๋ฅผ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์€ ์ •๋ง ์ข‹์€ ๋‚ด์šฉ์ด๋„ค์š”.

์ด๊ฒƒ์ด deep dive!๊ตฐ์š”.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜คํ˜ธ ๋‹ค๋“ค ์ธ๋ฑ์Šค๋‚˜ dropFirst๋ฅผ ์‚ฌ์šฉํ•˜์…จ๊ตฐ์š”

์ €๋Š” suffix๋กœ ๋ฝ‘์•„๋‚ด์คฌ์Šต๋‹ˆ๋‹ค!

for i in 1...S.count {
    words.append(String(S.suffix(i)))
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alstjr7437 ์™€ suffix prefix์— ๋Œ€ํ•œ ๊ธ€์„ ์จ๋†“๊ณ ๋„ ๊ทธ๊ฑธ ํ•˜... ์ €์˜ ์ด ํ•˜์ฐฎ์€ ์ค‘์ƒ์˜ ๋จธ๋ฆฌํ†ต์„ ํ•œ ๋ฒˆ ํƒ ! ์น˜๊ณ  ์–ต! ํ•˜๋‹ˆ ์ดํ•ดํ•ด๋ฒ„๋ฆฌ๋„ค์šง

}
Comment on lines +14 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ•€ ๋ง๋Œ€๋กœ swift๋‹ค์šด ๋А๋‚Œ์˜ ์ฝ”๋“œ์ธ ๊ฒƒ ๊ฐ™์•„์š”! ์‹œ์ž‘ ์ธ๋ฑ์Šค ์žก์•„์ฃผ๊ณ  ๋ฒ”์œ„์—ฐ์‚ฐ์ž ์จ์ฃผ๋Š”๊ฑฐ ์ข‹๋„ค์š”! ์ง๊ด€์ ์ด๋ฉด์„œ๋„ ๊ฐ„๊ฒฐํ•ฉ๋‹ˆ๋‹ค.
์นญ์ฐฌํ•ด ๋งˆ์นด๋กœ๋‹ˆ

์ „ ๋ฌธ์ž ์ˆœํšŒํ•˜๋ฉด์„œ ๋ฌธ์ž๋ฅผ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด์คฌ๋Š”๋ฐ ๋น„ํšจ์œจ์ ์ธ ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด๋“œ๋„ค์š”.. ์ฝ”๋“œ๋Š” ์ „์ฒด ๋ฆฌ๋ทฐ์— ๋‹ฌ๊ฒ ์Šต๋‹ˆ๋‹ค..!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forEach๋ฅผ ์“ฐ์‹œ๋‹ค๋‹ˆ ์—ญ์‹œ ๊ตฌํ˜„์™• ๋ฌด์ฐฌํ‚ด ๋ฌด์šฐ !!! sort(by:<) ์ง„์งœ {} () ์ด๋Ÿฐ์‹์œผ๋กœ ๋‚ด๋ถ€ ์กฐ๊ฑด๋“ค์„ ์†์‰ฝ๊ฒŒ ์Šค์œ„ํ”„ํ‹ฐํ•˜๊ฒŒ ๋ณ€๊ฒฝํ•˜๋˜๋ฐ ๋ฌด์šฐ์—๊ฒŒ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค.


array.sort()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ง„์งœ ๋ณ„๊ฑฐ ์•„๋‹Œ๋ฐ ์ €๋Š” sort๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ์ด์ง€๋งŒ ํ•ญ์ƒ by:<๋กœ ์ผ๋˜ ๊ฒƒ ๊ฐ™์•„์š”. ๊ทผ๋ฐ ๋ถˆํ•„์š” ํ•œ ๊ฒƒ ๊ฐ™๋„ค์š”! ์ €๋„ ๊ฐ„๊ฒฐํ•˜๊ฒŒ sort()๋กœ ํ‘œํ˜„ ํ•ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค.

res.sort(by: <)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"์˜คํžˆ๋ ค ์ข‹์•„"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"๊ทธ๋Ÿฐ๊ฐ€?"


for item in array {
print(item)
}

Comment on lines +14 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ธ€๋กœ๋‹ˆ ~~~~ ์š”!!

๋ฆฌ์–ผ๋ฃจ ์ •๋ง๋ฃจ ~ ์–ธ๋ƒ๋ž‘ ์ฝ”๋“œ๊ฐ€ ๋น„์Šทํ•œ๋ฐ ๋ญ ๊ฑฐ์ง„ ๋˜‘๊ฐ™๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ๊ฒ ์œผ์˜ˆ

import Foundation

let str = readLine()!

var strArray: [String] = [str]

for i in 1..<str.count {
    let startIndex = str.index(str.startIndex, offsetBy: i)
    let substring = String(str[startIndex...])
    strArray.append(substring)
}

for item in strArray.sorted(){
    print(item)
}

๊ทธ๋Ÿฐ๋ฐ ๋ญ”๊ฐ€ ์ € String์œผ๋กœ ํ•œ๋ฒˆ ๋” ๋ณต์‚ฌํ•ด์ฃผ๋Š”๊ฒŒ ๋ฉ”๋ชจ๋ฆฌ๋ž‘ ์‹œ๊ฐ„ ๋ณต์žก๋„์ƒ ์ค‘์ฒฉ์ด ๋˜๋Š”๊ฑฐ ๊ฐ™์•„์„œ print(type(of:))๋ฅผ ๊ฒ๋‚˜ ์ฐ์–ด๋ณด๋‹ˆ

์—ญ์‹œ๋‚˜ str[startIndex...] ๋Š” Substring์ด๋ผ๋Š” ํƒ€์ž…์ด ์กด์žฌํ•˜๋”๊ตฐ์š” ! ๊ทธ๋ž˜์„œ ์ฒซ๋ฒˆ์งธ ์š”์†Œ๋ถ€ํ„ฐ ๋‹ค ์ง‘์–ด๋„ฃ๋Š”๋‹ค ์ƒ๊ฐํ•˜๊ณ  ๋ฐฐ์—ด์„ ์• ์ดˆ์— Substring์œผ๋กœ ์„ ์–ธํ•˜๊ณ  ํ’€์–ด๋ณด๋‹ˆ ๋“ค์–ด๊ฐ€๋”๋ผ๊ตฌ์š” !!!

import Foundation

let str = readLine()!

var strArray: [Substring] = []

for i in 0..<str.count {
    let startIndex = str.index(str.startIndex, offsetBy: i)
    strArray.append(str[startIndex...])
//    print(type(of:str[startIndex...]))
}

for item in strArray.sorted(){
    print(item)
}

Xcode ์ž๋™์™„์„ฑ์“ฐ๋‹ˆ item ์ถ”์ฒœํ•ด์„œ ์ผ๋Š”๋ฐ ๊ธ€๋กœ๋‹ˆ๋„ ๊ทธ๋Ÿฐ๊ฑฐ์˜€๋‚˜์š”? ํฌํฌ ใ…‹ใ…‹

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://eunjin3786.tistory.com/458 substring ๊ด€๋ จ๊ธ€์ธ๋ฐ ์ฐธ๊ณ  ํ•˜์‹œ๋ฉด ์ข‹์„๋“ฏํ•ฉ๋‹ˆ๋‹ค ใ…Žใ…Ž

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(type(of:) ์ฐ๋Š” ์Šต๊ด€ ์กด๊ฒฝํ•ฉ๋‹ˆ๋‹ค ๋ฐ๋ฏธ๊ฐ“..ใ…œใ…œ

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์งค ๋„ˆ๋ฌด ์›ƒ๊ฒจ์š” ใ…‹ใ…‹ใ…‹ใ…‹

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ์•„๋‹ˆ ใ… ใ… ใ… 
๊ทผ๋ฐ ์ €๋Š” ๋ฌธ์ œ ํ’€๋ฉด์„œ ์ €๋ ‡๊ฒŒ ์‹œ๊ฐ„์ด ์–ผ๋งˆ๋‚˜ ๋ ๊นŒ .. ? ๋Š” ์ดˆ๊ณผ ๋์„ ๋•Œ๋‚˜ ํ™•์ธํ•˜๋Š”๋ฐ ์ง„์งœ ๋Œ€๋ฐ•์ 

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giljihun @MuchanKim @sep037 ์š”์‹œ!! ์ด์ฟ ์ฃ  !!!