프로그래머스 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/181950
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
import Foundation
let inp = readLine()!.components(separatedBy: [" "]).map { $0 }
let (s1, a) = (inp[0], Int(inp[1])!)
print(String(repeating: s1, count: a))
중요 개념
- 문자열을 주어진 횟수만큼 반복해서 출력하는 문제이다
init(
repeating repeatedValue: String,
count: Int
)
- repeating : 반복할 문자
- count : 반복할 횟수
https://developer.apple.com/documentation/swift/string/init(repeating:count:)-23xjt
init(repeating:count:) | Apple Developer Documentation
Creates a new string representing the given string repeated the specified number of times.
developer.apple.com
'알고리즘 > Programmers' 카테고리의 다른 글
[Swift_Programmes] 자릿수 더하기 (1) | 2023.11.20 |
---|---|
[Swift_Programmers] 특수문자 출력하기 (0) | 2023.11.18 |
[Swift_Programmers] 대소문자 바꿔서 출력하기 (0) | 2023.11.18 |
[Swift_Programmers] 정수 부분 (0) | 2023.11.18 |
[Swift_Programmers] rny_string (0) | 2023.11.18 |