알고리즘/Programmers

[Swift_Programmers] 문자열 반복해서 출력하기

YEN_ 2023. 11. 18. 16:38

 

 

프로그래머스 문제 링크 : 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