๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
3๏ธโƒฃ Swift/Problem Solving

[Swift Algorithm] ์ง์‚ฌ๊ฐํ˜• ๋ณ„์ฐ๊ธฐ Programmers(Lv.1)

by seolhee2750 2021. 6. 6.
๋ฌธ์ œ ์„ค๋ช…

์ด ๋ฌธ์ œ์—๋Š” ํ‘œ์ค€ ์ž…๋ ฅ์œผ๋กœ ๋‘ ๊ฐœ์˜ ์ •์ˆ˜ n๊ณผ m์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.
๋ณ„(*) ๋ฌธ์ž๋ฅผ ์ด์šฉํ•ด ๊ฐ€๋กœ์˜ ๊ธธ์ด๊ฐ€ n, ์„ธ๋กœ์˜ ๊ธธ์ด๊ฐ€ m์ธ ์ง์‚ฌ๊ฐํ˜• ํ˜•ํƒœ๋ฅผ ์ถœ๋ ฅํ•ด๋ณด์„ธ์š”.

 

์ œํ•œ ์กฐ๊ฑด
  • n๊ณผ m์€ ๊ฐ๊ฐ 1000 ์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ

 

๋ฌธ์ œ ํ’€์ด
import Foundation

let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! }
let (a, b) = (n[0], n[1])

for i in 0..<b {
    print(String(repeating : "*", count : a))
}
  • for๋ฌธ์„ ์ด์šฉ, *์„ a๊ฐœ์”ฉ ์ฐ๋Š” ๊ฒƒ์„ b๋ฒˆ ๋ฐ˜๋ณตํ–ˆ๋‹ค.
  • ๋ฐ˜๋ณต์€ repeating์„ ์‚ฌ์šฉํ•ด์ฃผ์—ˆ๋‹ค.

 

๐Ÿ’ก ํ”ผ๋“œ๋ฐฑ
  • ์ด์ „์— ํ•ด๊ฒฐํ–ˆ๋˜ 'ํ•ธ๋“œํฐ ๋ฒˆํ˜ธ ๊ฐ€๋ฆฌ๊ธฐ' ๋ฌธ์ œ์—์„œ ๋ฐฐ์› ๋˜ repeating์„ ์‚ฌ์šฉํ•˜๋‹ˆ
    ํ›จ์”ฌ ํŽธ๋ฆฌํ•˜๊ฒŒ ์ฝ”๋“œ๋ฅผ ์™„์„ฑํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

2021.06.06 - [๐Ÿ“ Algorithm with Swift/Programmers Lv1] - [Swift Algorithm] ํ•ธ๋“œํฐ ๋ฒˆํ˜ธ ๊ฐ€๋ฆฌ๊ธฐ Programmers(Lv.1)

 


 

๋ฌธ์ œ

https://programmers.co.kr/learn/courses/30/lessons/12969

๋Œ“๊ธ€