Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 문자열 반복
- 생명주기
- swift grammer
- willset
- 코딩테스트
- Swift 문법
- 랜덤추출
- didset
- lifecycle
- App구조
- Property Observer
- dismiss
- 공식문서
- SwiftUI
- navigationcontroller
- inout
- Swift
- LV0
- @main
- Stride
- 대소문자바꾸기
- 야곰아카데미
- 짝수의합
- IOS
- Swift문법
- @Binding
- @State
- propertWrappers
- randomElement
- 프로그래머스
Archives
- Today
- Total
miniworld
[Swift] 프로그래머스 Lv0. 문자 반복 출력하기 본문
문자열 반복해서 출력하기
for문을 이용
import Foundation
let inp = readLine()!.components(separatedBy: [" "]).map { $0 }
let (s1, a) = (inp[0], Int(inp[1])!)
for _ in 1...a {
print(s1, terminator: "")
}
출력 결과
입력값 〉 "string 5"
출력값 〉 "stringstringstringstringstring"
repeating 이용
import Foundation
let inp = readLine()!.components(separatedBy: [" "]).map { $0 }
let (s1, a) = (inp[0], Int(inp[1])!)
print(String(repeating: s1, count: a))
출력 결과
입력값 〉 "string 5"
출력값 〉 "stringstringstringstringstring"
'Swift > 프로그래머스 코딩테스트 연습' 카테고리의 다른 글
[Swift] 프로그래머스 Lv0. 공백으로 구분하기1 / split() 과 components() 구분! (0) | 2024.01.17 |
---|---|
[Swift] 프로그래머스 Lv0. 짝수의 합, for문 stride (0) | 2024.01.12 |
[Swift] 프로그래머스 Lv0. 대소문자 바꿔서 출력하기 (0) | 2023.07.12 |