Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/Baekjoon

[๋ฐฑ์ค€] (Swift) 11656๋ฒˆ - ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด

๊ฐ์ž ๐Ÿฅ” 2022. 2. 19. 12:24
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ๋งํฌ

https://www.acmicpc.net/problem/11656

 

11656๋ฒˆ: ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด

์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. S๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ธธ์ด๋Š” 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค.

www.acmicpc.net

 

๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด

  • for๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ ํ•œ๊ธ€์ž์”ฉ ๋นผ๊ณ  stringํ˜•ํƒœ์ธ word ๋ณ€์ˆ˜์— ๋„ฃ์–ด์ค€๋‹ค. abc -> bc -> c
  • word ๋ณ€์ˆ˜ ์ „๋ถ€๋ฅผ answer ๋ฐฐ์—ด์— push
  • answer ๋ฐฐ์—ด์„ sorted() ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ •๋ ฌ
  • for ๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ print
let line = Array(readLine()!)
var answer: [String] = []

for i in 0..<line.count {
    var word = ""
    for j in i..<line.count {
        word += String(line[j])
    }
    answer.append(word)
}
answer = answer.sorted()

for a in answer {
    print(a)
}
๋ฐ˜์‘ํ˜•