-
Notifications
You must be signed in to change notification settings - Fork 0
3-sep037 #13
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
Conversation
sep037/์ ๋ ฌ/BOJ_11656.swift
Outdated
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.
์ ๋ removeFirst() ์ฌ์ฉํด์คฌ๋๋ฐ, String.index์ฌ์ฉํด์ sliceํ์ ๊ฒ ๋ swift๋ค์ด๋๋์ด๋ค์..!
์ด๊ฑฐ๋ก ์ฑ๋ฅ๋น๊ต๋ฅผ ํ๋ฒํด๋ดค๋๋ฐ ์๋ ๋ ์์ธํ ๋จ๊ฒจ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค !
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.
@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)
}
๋น์ทํ๋ ค๋์ ? ๋ฒค์น๋งํน ๊ฐ๋ฅํ์ ๊ฐ์ ?
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.
์ ๋ dropFirst() ๋ฅผ ์ฌ์ฉํด๋ดค๋๋ฐ์.
dropFirst()๋ ์ ๋ฌธ์๋ฅผ ๊ฑด๋๋ด Substring์ ๋ฆฌํดํ๊ธฐ ๋๋ฌธ์ ์ฆ์ ๋ณต์ฌ๊ฐ ์ผ์ด๋์ง ์์ง๋ง,
๊ทธ๊ฑธ ๋ค์ String()์ผ๋ก ๋ณํํด์ ์ ์ฅํ๊ฒ ๋๋ฉด, ๊ทธ ์์ ์์๋ง ๋ณต์ฌ๊ฐ ๋ฐ์ํ๊ฒ ๋ฉ๋๋ค.
๊ทธ๋์ ์ฒ์์ ์ด ๋ฐฉ์์ด ์ต์ ์ด๊ฒ ๊ตฌ๋? ์ถ์๋๋ฐ.
๋ง์ํ์ removeFirst() ๋ฐฉ์์ด COW ์กฐ๊ฑด์์ ํฌ์ธํฐ๋ง ์ด๋ํ๋ ์์ผ๋ก ์ฒ๋ฆฌ๋ผ์
์ค์ ๋ก๋ ๋ ๋น ๋ฅผ ์ ์๋ค๋ ์ ์ ์ ๋ง ์ข์ ๋ด์ฉ์ด๋ค์.
์ด๊ฒ์ด deep dive!๊ตฐ์.
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.
์คํธ ๋ค๋ค ์ธ๋ฑ์ค๋ dropFirst๋ฅผ ์ฌ์ฉํ์ จ๊ตฐ์
์ ๋ suffix๋ก ๋ฝ์๋ด์คฌ์ต๋๋ค!
for i in 1...S.count {
words.append(String(S.suffix(i)))
}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.
@alstjr7437 ์ suffix prefix์ ๋ํ ๊ธ์ ์จ๋๊ณ ๋ ๊ทธ๊ฑธ ํ... ์ ์ ์ด ํ์ฐฎ์ ์ค์์ ๋จธ๋ฆฌํต์ ํ ๋ฒ ํ ! ์น๊ณ ์ต! ํ๋ ์ดํดํด๋ฒ๋ฆฌ๋ค์ง
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.
์ค๋ช ํธ์์ ํจ์์ด๋ฆ์ ์ ์ด๋ฆ์ผ๋ก ํ์ด์ !
func finn(_ str: String) {
var answer: [String] = [str]
var changableStr = str
for _ in 0 ..< str.count - 1 {
changableStr.removeFirst()
answer.append(changableStr)
}
answer.sort()
for item in answer {
print(item)
}
}์ ๋ answer๋ฐฐ์ด์๋ค๊ฐ ๋ฌธ์ ์์ ์๋ํ๋๋ก ์์ ํ๋์ฉ
removeFirst()๋ฅผ ํตํด์ ์์์ ํ๊ธ์์ฉ ๋ผ๋จน์ผ๋ฉด์ ๋ฐฐ์ด์ ๋ฃ๊ณ sorting์ผ๋ก ๋๋ ธ์ด์!
์ผ๋ฐ์ ์ผ๋ก๋ ์์์ ๋ผ์ด๊ฐ๋ฉด O(N)๋งํผ ์ด์ ๋ค์์ ๋ค์ด ๋ก๊ฒจ์ ธ์์ผํ๋๊ฒ์ผ๋ก ์์์, ๋น์ฐํ ์ ์ฝ๋๊ฐ ๊ธ๋ก๋์ฝ๋๋ณด๋ค ๋๋ฆฌ๋ค๊ณ ์๊ฐ์ ํ๋๋ฐ์..!
let alphabet = "abcdefghijklmnopqrstuvwxyz"
let testInput = String((0 ..< 4000).map { i in
alphabet[alphabet.index(alphabet.startIndex, offsetBy: i % alphabet.count)]
})
var totalFinn = 0.0
var totalGlowny = 0.0
for _ in 0 ..< 100 {
var start = CFAbsoluteTimeGetCurrent()
finn(testInput)
var end = CFAbsoluteTimeGetCurrent()
totalFinn += (end - start)
start = CFAbsoluteTimeGetCurrent()
glowny(testInput)
end = CFAbsoluteTimeGetCurrent()
totalGlowny += (end - start)
}
print("Finn ํ๊ท : \(totalFinn / 100)์ด")
print("Glowny ํ๊ท : \(totalGlowny / 100)์ด")์ด๊ฑฐ๋ก ์ด์ ๋ฒค์น๋งํน์ ๋๋ ค๋ดค๊ฑฐ๋ ์!
์ํ๋ฒณ ์์๋๋ก ๋ฐ๋ณต๋๋ 4000์ ๊ธธ์ด์ ๋ฌธ์์ด์ ํ์ฉํ ๊ฒ์ผ๋ก ๋๋ ค๋ดค์ต๋๋ค!
(1000์๋ ๋๋ฌด ๋๋ฆฐ๊ฒ๊ฐ์์ 10000์๊น์ง ๋๋ ธ๋๋ ์ด๊ฒ ๋๋ฌด ๊ฐ์ด ์๋์ค๊ธธ๋ ๋๊ฐ 4์ฒ์ ์ ๋๋ก ํฉ์๋ฅผ ๋ดค์ต๋๋ค..)
๊ทธ๋ฌ๋๋ ๊ฒฐ๊ณผ๊ฐ์ด ์๋์ ๊ฐ์ด ๋์ค๋๋ผ๊ตฌ์..!
Finn ํ๊ท : 0.009801552295684815์ด
Glowny ํ๊ท : 0.023117616176605224์ด

String.index์์ฒด๊ฐ ์์์ ์ฐจ๋ก๋๋ก ๋ณด๋๊น O(i)๊ธฐ๋ ํ๊ณ ,
String(suffix)ํ ๋ ์ด๊ฒ ๋ ๋ณต์ฌํ๋ ๊ฐ์ด ๋ง์ด๋ ๋ค๊ณ ํ๋๋ผ๊ตฌ์..!
Substring to String ์ฌ๊ธฐ์์ Substring to String ์น์ ๋ณด์๋ฉด ์ด๋ป๊ฒ String()์ด ๋์ํ๋์ง ์ค๋ช ์ด ๋์ด์์ต๋๋ค..! ์ ๋ ๋ณต์กํด์ ์์ ์ดํด๋ ๋ชปํ๋๋ฐ,
- ์๋ณธ ๋ฌธ์์ด ์ฐธ์กฐํ๊ณ
- startIndex, endIndex ์ฌ๋ผ์ด์คํ๊ณ
- ์ฌ๋ผ์ด์คํ ๋ฒํผ๋ฅผ ์๋ก ๋ณต์ฌํด์ String์ ๋ง๋ ๋์ฉ
์ฒ์์ ์ ๊ฐ ์ฌ์ฉํ removeFirst()์ด ์ผ๋ฐ์ ์ผ๋ก๋ ๋๋ฆด ๊ฑฐ๋ผ๊ณ ์๊ฐํ์ด์. String()๊น์ง ๋ณต์ก๋๋ ์๊ฐ์ํด์ฃผ๊ธฐ๋ ํ๊ณ ..
๋ฐฐ์ด์ฒ๋ผ ์์์ ๊ฐ์ ์ ๊ฑฐํ๋ฉด ๋ค์ ์๋ ๋ชจ๋ ์์๋ฅผ ํ ์นธ์ฉ ๋ก๊ฒจ์ผ ํ๋๊น ๋นํจ์จ์ ์ธ ๋ฐฉ์์ด์์์? ๋ค์์ ๋นผ๋๊ฒ๋ณด๋ค.. ๊ทธ๋์ ์ข ์์๋ณด๋ค๊ฐ COW๋ผ๋ ํค์๋์ ๋ํด์ ์กฐ๊ธ ์์๋ดค์ต๋๋ค..
Swift์ String (Array,Dictionary,Set๋ ๊ฐ๋ฅ) ์ ๋ด๋ถ์ ์ผ๋ก Copy-on-Write(COW)๊ฐ ์ ์ฉ๋ ์ ์๋ค๊ณ ํ๋๋ฐ์..! COW ๊ด๋ จ ๋ธ๋ก๊ทธ
๊ทผ๋ฐ ํด๋น ๋ฌธ์์ด์ ์ฐธ์กฐ๊ฐ ์ ์ผํ๋ค๋ฉด, removeFirst()๋ฅผ ์จ๋ COW๊ฐ ์ผ์ด๋์ง์๊ณ , ๊ทธ๋ฅ ์ฌ๋ผ์ด์ค ์์ ํฌ์ธํฐ๋ง ํ ์นธ ์ฎ๊ธฐ๋ ์์ผ๋ก ๋งค์ฐ ๋น ๋ฅด๊ฒ ์ฒ๋ฆฌํ ์ ์๋๋ผ๊ณ ์.
์ด๋ด ๋ ์๊ฐ๋ณต์ก๋๊ฐ O(N)์ด ์๋๋ผ, ๊ฑฐ์ O(1)์ ๊ฐ๊น๊ฒ ๋์ํ ์๋ ์๋ค๋ค์ ! (์ ๊ธฐ)
์์ฝํ๋ฉด ๋ณต์ฌํ์ง ์๋ ์ด์, ์์ ๊น์ง๋ ๋งค์ฐ ๋น ๋ฅด๊ฒ ์ฒ๋ฆฌ๋ ์ ์๋ค์ ๋งฅ๋ฝ? ์ ๋๋ก ์ดํดํด์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์. <๊ทธ๋งํผ ๋ณต์ฌํ๋๋ฐ์ ๋ฆฌ์์ค๊ฐ ๋๋ ๋ค๋ ๊ฐ๋
>
๋ฌผ๋ก ๊ทธ๋ ๋ค๊ณ ํด์ COW๊ฐ ์ ์ผ์ด๋๋ค -> ๋ฌด์กฐ๊ฑด ๋น ๋ฅด๋ค๋ ๊ฑด ๋ ์๋๋ผ๋ค์...(์๋ชจ๋ฅด๋ ๋ถ์ผ๋ผ์ ๋ง์ด ํท๊ฐ๋ฆฌ๋๋ฐ ๋๋๋ง ๋ด์ฃผ์๊ธธ..)
COW๋ก ์๋ก ๋ณต์ฌ๋ ๋ฒํผ๊ฐ ์คํ๋ ค ๋ ์บ์ ์นํ์ ์ธ ๊ตฌ์กฐ๊ฐ ๋ ์๋ ์๊ณ ,
์ ๊ทผ ํจํด์ ๋ฐ๋ผ ์ฑ๋ฅ์ด ๋ค์งํ๋ ๊ฒฝ์ฐ๋ ์กด์ฌํ๋คํฉ๋๋ท..
์ ๋ ๋ธ๋ก๊ทธ์ฌ๋ฌ๊ฐ๋ GPT์ ์๋์ด๋ ์ฌ๋ฌ๊ฐ ๋ค์ง๋ฉด์ ์ข ๋์์ด ๋์์ผ๋ฉดํด์ ์จ๋ดค๋๋ฐ ์ข ์ค๊ตฌ๋๋ฐฉ์ธ๊ฒ ๊ฐ๋ค์..
์ฒจ๋ถํ ๋งํฌ ๋ณด์๊ณ ๋์์ด ๋์๋ฉดํฉ๋๋ค..! ํ๋ ธ๋ค๋ฉด ์ง์ ๋ ๋ถํ๋๋ ค์..!
์ถ๊ฐ
isKnownUniquelyReferenced
๋ก ์ฐธ์กฐ๊ฐ ํ๋์ธ์ง ์ ์ ์์
MuchanKim
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.
์ด๋ฒ ์ฃผ์ฐจ๋ถํฐ๋ ํ์์ดํ์ผ๋ก ํ๋ฒ ํ์ด๋ณด๋ ค๊ณ ํด์. ๊ธฐ์กด์ ๋ค์ด๋ฐ์ด๋ ๋ชจ๋๋ก ๋ฐ๋ก ๋นผ๋๊ฒ ์๊ฐ์ ๋ ์ฐ๋ ๊ฒ ๊ฐ๊ธฐ๋ํด์.. ๋ฌดํผ ์ด ๋ฌธ์ ๋ 20๋ถ?์ ๋ ๊ฑธ๋ฆฐ ๊ฒ ๊ฐ์ต๋๋ค. ๋ค๋ฅธ๋ถ๋ค ์ฝ๋๋ณด๋ฉด ์์ง Swift๋ต์ง์๊ฒ ํธ๋ ๊ฒ ๊ฐ๋ค์..ใ .ใ
์ 2์ฐจ์ ๋ฐ๋ณต๋ฌธ์ผ๋ก ํ์์ต๋๋ค. ๋จผ์ 0..., 1... ์ผ๋ก ์ธ๋ฑ์ค๋ฅผ ์ฌ๋ผ์ด์ฑ ํ๋ ค๊ณ ํ๊ณ ์ต์ํ ๋ฐฉ๋ฒ์ผ๋ก ํผ ๊ฒ ๊ฐ์์. ๋ง์นด๋ก๋์จ์ startIndex๊ฐ ์ ํํ j๋ผ๊ณ ๋ณด๋ฉด ๋๊ณ , ์ ๋ j๋ถํฐ ์ํํด์ ๋ฌธ์๋ฅผ ๋ํด์ ๋ฌธ์์ด์ ๋ง๋ค์ด ์คฌ์ด์.
๊ฒฐ๋ก ์.. ๋ฉ๋ชจ๋ฆฌํจ์จ์ด๋ ์๋ ๋ ๋ค ์๊ฐํ์ง ๋ชปํ ์ฝ๋๋ผ๊ณ ๋ณผ ์ ์๊ฒ ์ต๋๋ค.
+ ๊ธธ์ด forEach ์ ํ์ฉํ๊ธธ๋ ์ ๋ ์จ๋ดค์ต๋ฉ๋ค.
import Foundation
// ๋ฌธ์์ด ๋ฐฐ์ด์ผ๋ก ๋ฐ๊ณ ์ ๊ธ์ ํ๋์ฉ ๋ ๋ฆฌ๋ฉด์ ๋จ์ด ๋ง๋ค์ด ์ฃผ๋ฉด ๋ ๋ฏ.
// ๊ทธ๋ฆฌ๊ณ ๋ง๋ ๋จ์ด ๋ฆฌ์คํธ ์ค๋ฆ์ฐจ์ sort
let n = Array(readLine()!.lowercased())
var res: [String] = []
for i in 0..<n.count {
var word: String = ""
for j in i..<n.count {
word += String(n[j])
}
res.append(word)
}
res.sort(by: <)
res.forEach { i in print(i) }
sep037/์ ๋ ฌ/BOJ_11656.swift
Outdated
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๋ค์ด ๋๋์ ์ฝ๋์ธ ๊ฒ ๊ฐ์์! ์์ ์ธ๋ฑ์ค ์ก์์ฃผ๊ณ ๋ฒ์์ฐ์ฐ์ ์จ์ฃผ๋๊ฑฐ ์ข๋ค์! ์ง๊ด์ ์ด๋ฉด์๋ ๊ฐ๊ฒฐํฉ๋๋ค.
์นญ์ฐฌํด ๋ง์นด๋ก๋
์ ๋ฌธ์ ์ํํ๋ฉด์ ๋ฌธ์๋ฅผ ์๋ก ๋ง๋ค์ด์คฌ๋๋ฐ ๋นํจ์จ์ ์ธ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด๋๋ค์.. ์ฝ๋๋ ์ ์ฒด ๋ฆฌ๋ทฐ์ ๋ฌ๊ฒ ์ต๋๋ค..!
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.
forEach๋ฅผ ์ฐ์๋ค๋ ์ญ์ ๊ตฌํ์ ๋ฌด์ฐฌํด ๋ฌด์ฐ !!! sort(by:<) ์ง์ง {} () ์ด๋ฐ์์ผ๋ก ๋ด๋ถ ์กฐ๊ฑด๋ค์ ์์ฝ๊ฒ ์ค์ํํฐํ๊ฒ ๋ณ๊ฒฝํ๋๋ฐ ๋ฌด์ฐ์๊ฒ ๋ฐฐ์๊ฐ๋๋ค.
sep037/์ ๋ ฌ/BOJ_11656.swift
Outdated
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.
์ง์ง ๋ณ๊ฑฐ ์๋๋ฐ ์ ๋ sort๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค๋ฆ์ฐจ์์ด์ง๋ง ํญ์ by:<๋ก ์ผ๋ ๊ฒ ๊ฐ์์. ๊ทผ๋ฐ ๋ถํ์ ํ ๊ฒ ๊ฐ๋ค์! ์ ๋ ๊ฐ๊ฒฐํ๊ฒ sort()๋ก ํํ ํด์ผ๊ฒ ์ต๋๋ค.
res.sort(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.
"์คํ๋ ค ์ข์"
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.
sep037/์ ๋ ฌ/BOJ_11656.swift
Outdated
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
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 ์ถ์ฒํด์ ์ผ๋๋ฐ ๊ธ๋ก๋๋ ๊ทธ๋ฐ๊ฑฐ์๋์? ํฌํฌ ใ ใ
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.
https://eunjin3786.tistory.com/458 substring ๊ด๋ จ๊ธ์ธ๋ฐ ์ฐธ๊ณ ํ์๋ฉด ์ข์๋ฏํฉ๋๋ค ใ ใ
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.
print(type(of:) ์ฐ๋ ์ต๊ด ์กด๊ฒฝํฉ๋๋ค ๋ฐ๋ฏธ๊ฐ..ใ ใ
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.
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
์๋ ใ
ใ
ใ
๊ทผ๋ฐ ์ ๋ ๋ฌธ์ ํ๋ฉด์ ์ ๋ ๊ฒ ์๊ฐ์ด ์ผ๋ง๋ ๋ ๊น .. ? ๋ ์ด๊ณผ ๋์ ๋๋ ํ์ธํ๋๋ฐ ์ง์ง ๋๋ฐ์
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.
@giljihun @MuchanKim @sep037 ์์!! ์ด์ฟ ์ฃ !!!
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
๋ช
์ฌ์ธ์ดํ
ํ์์ด๋ฅผ ๋ง๋๋ ํํ์์ ํ๋. ์ด๋ค ๋จ์ด์ ๋์ ๋ถ์ด ์๋ก์ด ๋จ์ด๊ฐ ๋๊ฒ ํ๋ ๋ง. `๊ฐ์์ง'์ `-์ง' ๋ฐ์. ๋๊ฐ์ง. ๋ท๊ฐ์ง. ๋ฐ๊ฐ์ง. ์ ๋ฏธ์ด. ใ๋ถใ ๋ค๋ถ์ด. โ์ ๋์ฌ.
-> ๋ญ์ง ์ด๊ฑฐ. '์ ๋ฏธ์ฌ'๋ผ๋ ํํ์ ์จ๋ ๋๋ ๋ฌธ์ ๊ฐ
*/
import Foundation
guard let S = readLine() else { exit(0) }
let chars = Array(S)
var result: [String] = []
for i in 0..<chars.count {
var temp = ""
for j in i..<chars.count {
temp += String(chars[j])
}
result.append(temp)
}
print(result.sorted().joined(separator: "\n"))dropFirst() ํ์ฉํด๋ณด๊ธฐ
import Foundation
guard let S = readLine() else { exit(0) }
let chars = Array(S)
var result: [String] = []
for i in 0..<S.count {
result.append(String(S.dropFirst(i)))
}
print(result.sorted().joined(separator: "\n"))๊ธฐ์กด ์ด์คํฌ๋ฌธ์ ๋งค ๋ฃจํ๋ง๋ค ์๋ก์ด ๋ฌธ์์ด์ ์์ฑํ๋๋ฐ
dropFirst()๋ฅผ ์ฐ๋ String() ๋ณํ์ ํ ๋๋ง ๋ณต์ฌ๊ฐ ๋ฐ์ํด์ ํจ์ฌ ์ฑ๋ฅ์ ์ข์ ๊ฒ ๊ฐ๊ณ ์ง๊ด์ ์ด์ฃ .
๋ฒ์ธ1
import Foundation
guard let S = readLine() else { exit(0) }
let chars = Array(S)
var result: [String] = []
print((0..<S.count).map { String(S.dropFirst($0)) }.sorted().joined(separator: "\n"))๋ฒ์ธ2
import Foundation
guard let S = readLine() else { exit(0) }
let chars = Array(S)
var result: [String] = []
(0..<S.count).map { String(S.dropFirst($0)) }.sorted().forEach { print($0) }์ด๊ฑด forEach๋ก print๋ฅผ ๋ถ๋ฌ์ .joined๋ฅผ ์์ฐ๋ฉด์ ๊ทนํ์ผ๋ก ์ค์ด๊ธฐ ใ ใ
sep037/์ ๋ ฌ/BOJ_11656.swift
Outdated
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์ String.index๋ฅผ ์ ํ์ฉํ ๋ฌธ์ ๊ณ ํ์ด๋ ๊น๋ํ๋ค์ด ~. ~
์ฌ์ํ ๋ถ๋ถ์ธ๋ฐ, ์ ๋
let num = N.count ๋ถ๋ถ์ด ์กฐ๊ธ์ ์ถ์์ ์ด์ง ์๋ ์ถ์ต๋๋ค!
length, stringLength ์ด๋ฐ๊ฑด ์ด๋จ๊น์??
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 array: [String] = []๋ ๊ฒฐ๊ตญ ๋ฆฌํด์ฉ์ด๋ผ๋ฉด result๋ answer๋ ๊ด์ฐฎ์๋ณด์ด๊ตฌ์!
ํน์, ๊ตฌ์กฐ๋ฅผ ์ค๋ช
ํ๋ค๋ฉด suffixes?์ด๋ฐ๊ฑฐ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค~!!
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.
@giljihun dropfirst(), ropfirst(),opfirst(),pfirst(),first(),irst(),rst(),st(),t()
alstjr7437
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.
์๋ ์ฌ์ด ๋ฌธ์ ์ ๋ญ์ด๋ฆฌ ์ฝ๋ฉํธ๊ฐ ๋ง์ง ํ๊ณ ๋ณด๋๊น
์ฌ๋ฌ๊ฐ์ง ์ธ๋ฑ์ค์ removeFirst ๋ฑ deep Dive์ ํฅ์ฐ์ด ์์๊ตฐ์!!
๋ง์ง๋ง์ ์ฝ์ด์ ๋ค๋ค ์ฌ๋ฐ์์ต๋๋ค!!
์ ๋ suffix๋ก ๋ฌธ์๋ฅผ ๋ฝ์์คฌ์ด์!
let S = readLine()!
var words: [String] = []
for i in 1...S.count {
words.append(String(S.suffix(i)))
}
words.sort()
for word in words {
print(word)
}
sep037/์ ๋ ฌ/BOJ_11656.swift
Outdated
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.
์คํธ ๋ค๋ค ์ธ๋ฑ์ค๋ dropFirst๋ฅผ ์ฌ์ฉํ์ จ๊ตฐ์
์ ๋ suffix๋ก ๋ฝ์๋ด์คฌ์ต๋๋ค!
for i in 1...S.count {
words.append(String(S.suffix(i)))
}
๐ ๋ฌธ์ ๋งํฌ
์ ๋ฏธ์ฌ ๋ฐฐ์ด

๊ทธ๋ฅ ์๊ฐ ํ ์๊ฐ๋ค ๋ ์ฐ์๋ผ๊ณ ์ ๋ ฌ .. ๊ฐ์ ธ์์ด์
โ๏ธ ์์๋ ์๊ฐ
5๋ถ ใ
โจ ์๋ ์ฝ๋
์ฑ์์์ด๋ณด์ผ์์์ง๋ง..
๋ฌธ์์ด์ ์ ๋ ฅ๋ฐ๋๋ค.
๋น ๋ฐฐ์ด์ ๋ง๋ ๋ค. (์ฌ๋ผ์ด์ฑ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ๋ฐฐ์ด)
๋ฌธ์์ด ๊ธธ์ด๋งํผ ๋ฐ๋ณตํ๋ฉด์:
a. ํ์ฌ ์ธ๋ฑ์ค๋ถํฐ ๋๊น์ง ๋ฌธ์์ด์ ์ฌ๋ผ์ด์ฑํ๋ค.
b. ์ฌ๋ผ์ด์ฑํ ๋ฌธ์์ด์ ๋ฐฐ์ด์ ์ถ๊ฐํ๋ค.
๋ฐฐ์ด์ ์ ๋ ฌํ๋ค.
๋ฐฐ์ด์ ๋ชจ๋ ์์๋ฅผ ์ถ๋ ฅํ๋ค.
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
์ ๋ ๊ทธ๋ฅ sort๊ฐ ๋ชจ๋ ๋ฌธ์์ด ์๋๋ก ์ ๋ ฌํ๋์ง๋ฅผ ๊น๋จน๊ณ
๊ทธ๋ฅ ์ฒซ ๊ธ์ ์ ๋ ฌํ๊ณ ๊ทธ ๋ค์ ๋ ๋ฒ์งธ ์ ๋ ฌํ๊ณ ๊ทธ๋ฌ๋ค๊ฐ ๊ทธ๋ฅ sort ํจ์ ์ฌ์ฉํ์ด์ฉ
์ด์ผ ์ด๊ฑธ ๊น๋จน์ง ?