-
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
3-sep037 #13
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,25 @@ | ||
| // | ||
| // main.swift | ||
| // 11656 | ||
| // | ||
| // Created by Seungeun Park on 4/28/25. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| let N = readLine()! | ||
| let num = N.count | ||
| 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
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
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~ ์ญ์ ์ง์ด๋ค์ ๋ฐ์ ์ฝ๋ ๋ณด๊ณ ์๋๋ฐ์ ์ ๊ฐ ๋ฌธ์์ด ํ๋๋ 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)
}
๋น์ทํ๋ ค๋์ ? ๋ฒค์น๋งํน ๊ฐ๋ฅํ์ ๊ฐ์ ?
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. ์ ๋ dropFirst() ๋ฅผ ์ฌ์ฉํด๋ดค๋๋ฐ์. dropFirst()๋ ์ ๋ฌธ์๋ฅผ ๊ฑด๋๋ด Substring์ ๋ฆฌํดํ๊ธฐ ๋๋ฌธ์ ์ฆ์ ๋ณต์ฌ๊ฐ ์ผ์ด๋์ง ์์ง๋ง, ๋ง์ํ์ removeFirst() ๋ฐฉ์์ด COW ์กฐ๊ฑด์์ ํฌ์ธํฐ๋ง ์ด๋ํ๋ ์์ผ๋ก ์ฒ๋ฆฌ๋ผ์ ์ด๊ฒ์ด deep dive!๊ตฐ์.
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. ์คํธ ๋ค๋ค ์ธ๋ฑ์ค๋ dropFirst๋ฅผ ์ฌ์ฉํ์ จ๊ตฐ์ ์ ๋ suffix๋ก ๋ฝ์๋ด์คฌ์ต๋๋ค! for i in 1...S.count {
words.append(String(S.suffix(i)))
}
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. @alstjr7437 ์ suffix prefix์ ๋ํ ๊ธ์ ์จ๋๊ณ ๋ ๊ทธ๊ฑธ ํ... ์ ์ ์ด ํ์ฐฎ์ ์ค์์ ๋จธ๋ฆฌํต์ ํ ๋ฒ ํ ! ์น๊ณ ์ต! ํ๋ ์ดํดํด๋ฒ๋ฆฌ๋ค์ง |
||
| } | ||
|
Comment on lines
+14
to
+18
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. ํ ๋ง๋๋ก swift๋ค์ด ๋๋์ ์ฝ๋์ธ ๊ฒ ๊ฐ์์! ์์ ์ธ๋ฑ์ค ์ก์์ฃผ๊ณ ๋ฒ์์ฐ์ฐ์ ์จ์ฃผ๋๊ฑฐ ์ข๋ค์! ์ง๊ด์ ์ด๋ฉด์๋ ๊ฐ๊ฒฐํฉ๋๋ค. ์ ๋ฌธ์ ์ํํ๋ฉด์ ๋ฌธ์๋ฅผ ์๋ก ๋ง๋ค์ด์คฌ๋๋ฐ ๋นํจ์จ์ ์ธ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด๋๋ค์.. ์ฝ๋๋ ์ ์ฒด ๋ฆฌ๋ทฐ์ ๋ฌ๊ฒ ์ต๋๋ค..!
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. forEach๋ฅผ ์ฐ์๋ค๋ ์ญ์ ๊ตฌํ์ ๋ฌด์ฐฌํด ๋ฌด์ฐ !!! sort(by:<) ์ง์ง {} () ์ด๋ฐ์์ผ๋ก ๋ด๋ถ ์กฐ๊ฑด๋ค์ ์์ฝ๊ฒ ์ค์ํํฐํ๊ฒ ๋ณ๊ฒฝํ๋๋ฐ ๋ฌด์ฐ์๊ฒ ๋ฐฐ์๊ฐ๋๋ค. |
||
|
|
||
| array.sort() | ||
|
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. ์ง์ง ๋ณ๊ฑฐ ์๋๋ฐ ์ ๋ sort๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค๋ฆ์ฐจ์์ด์ง๋ง ํญ์ by:<๋ก ์ผ๋ ๊ฒ ๊ฐ์์. ๊ทผ๋ฐ ๋ถํ์ ํ ๊ฒ ๊ฐ๋ค์! ์ ๋ ๊ฐ๊ฒฐํ๊ฒ sort()๋ก ํํ ํด์ผ๊ฒ ์ต๋๋ค. res.sort(by: <)
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. "์คํ๋ ค ์ข์"
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 item in array { | ||
| print(item) | ||
| } | ||
|
|
||
|
Comment on lines
+14
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. ๊ธ๋ก๋ ~~~~ ์!! ๋ฆฌ์ผ๋ฃจ ์ ๋ง๋ฃจ ~ ์ธ๋๋ ์ฝ๋๊ฐ ๋น์ทํ๋ฐ ๋ญ ๊ฑฐ์ง ๋๊ฐ๋ค๊ณ ํ ์ ์๊ฒ ์ผ์ 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 ์ถ์ฒํด์ ์ผ๋๋ฐ ๊ธ๋ก๋๋ ๊ทธ๋ฐ๊ฑฐ์๋์? ํฌํฌ ใ ใ
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. https://eunjin3786.tistory.com/458 substring ๊ด๋ จ๊ธ์ธ๋ฐ ์ฐธ๊ณ ํ์๋ฉด ์ข์๋ฏํฉ๋๋ค ใ ใ
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. print(type(of:) ์ฐ๋ ์ต๊ด ์กด๊ฒฝํฉ๋๋ค ๋ฐ๋ฏธ๊ฐ..ใ ใ
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. ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
์๋ ใ
ใ
ใ
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. @giljihun @MuchanKim @sep037 ์์!! ์ด์ฟ ์ฃ !!! |
||
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๋ฅผ ์ ํ์ฉํ ๋ฌธ์ ๊ณ ํ์ด๋ ๊น๋ํ๋ค์ด ~. ~
์ฌ์ํ ๋ถ๋ถ์ธ๋ฐ, ์ ๋
๋ถ๋ถ์ด ์กฐ๊ธ์ ์ถ์์ ์ด์ง ์๋ ์ถ์ต๋๋ค!
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.
๋ ๊ฒฐ๊ตญ ๋ฆฌํด์ฉ์ด๋ผ๋ฉด 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.
๋ญ์ผ ์ด ๋ฉ์์ด๋
Uh oh!
There was an error while loading. Please reload this page.
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()