๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“– Problem Solution/Programmers

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ง์‚ฌ๊ฐํ˜• ๋ณ„์ฐ๊ธฐ Swift

by Fomagran ๐Ÿ’ป 2020. 3. 1.
728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ์„ค๋ช…

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


์ œํ•œ ์กฐ๊ฑด

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

์˜ˆ์‹œ

์ž…๋ ฅ

5 3

์ถœ๋ ฅ

*****

*****

*****

ํ’€์ด:a๋งŒํผ์˜ *์„ ๋งŒ๋“ค๊ณ  b๋งŒํผ ๋ฐ˜๋ณตํ•ด์„œ ๋”ํ•ด์ค€ ๋’ค ์ถœ๋ ฅํ•จ 1์ผ ๊ฒฝ์šฐ์—” for๋ฌธ์—์„œ 1...0์ด ๋˜๋ฏ€๋กœ 1์ผ ๊ฒฝ์šฐ๋งŒ ๊ทธ๋ƒฅ ์ถœ๋ ฅ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import Foundation
 
let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! }
let (a, b) = (n[0], n[1])
var s = String(repeating: "*", count:a)
var answer = String(repeating: "*", count: a)
if b == 1 {
    print(answer)
}else{
for _ in 1...b-1{
    s += "\n\(answer)"
}
print(s)
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

๋‹ค๋ฅธ ์‚ฌ๋žŒ ํ’€์ด ์ค‘ ๊ฐ€์žฅ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š” ๊ฒƒ

๊ฑ for๋ฌธ์œผ๋กœ b๋งŒํผ ์ถœ๋ ฅํ•˜๋ฉด ๋๋„ค..

1
2
3
4
5
6
7
8
import Foundation
 
let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! }
let (a, b) = (n[0], n[1])
 
for _ in 0..<b {
    print(String(repeating: "*", count: a))
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€