Algorithm/BAEKJOON
[백준 알고리즘/python3] 2675번 문자열 반복 문제풀이
찐무
2021. 1. 21. 16:13
728x90
반응형

문제
2675번: 문자열 반복
문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오. 즉, 첫 번째 문자를 R번 반복하고, 두 번째 문자를 R번 반복하는 식으로 P를 만들면 된다
www.acmicpc.net
문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 테스트 케이스의 개수 T (1 ≤ T ≤ 1,000)가 주어진다. 각 테스트 케이스는 반복 횟수 R (1 ≤ R ≤ 8), 문자열 S가 공백으로 구분되어 주어진다. S의 길이는 적어도 1이며, 20글자를 넘지 않는다.
출력
각 테스트 케이스에 대해 P를 출력한다.
예제 입력 | 예제 출력 |
2 3 ABC 5 /HTP |
AAABBBCCC /////HHHHHTTTTTPPPPP |
<정답 1>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T = int(input()) # 테스트 케이스 | |
for i in range(T): | |
R, S = input().split() | |
Slist = list(map(str, S)) | |
for j in range(len(Slist)): | |
result = Slist[j] * int(R) | |
print(result, end='') | |
print() |
<정답 2>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T = int(input()) # 테스트 케이스 | |
for i in range(T): | |
R, S = input().split() | |
Slist = str(S) | |
for j in range(len(Slist)): | |
result = Slist[j] * int(R) | |
print(result, end='') | |
print() |
※ 문자열은 리스트로 만들기 위해 굳이 list(map(str, S)) 를 사용하지 않고 str(S) 로 간단하게 해결된다.
728x90
반응형