ALGORITHM 🤖/Baekjoon

백준 - 2675

daxx0ne 2023. 4. 18. 11:37

https://www.acmicpc.net/problem/2675

 

2675번: 문자열 반복

문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오. 즉, 첫 번째 문자를 R번 반복하고, 두 번째 문자를 R번 반복하는 식으로 P를 만들면 된다

www.acmicpc.net

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int r = sc.nextInt();
            String s = sc.next();
            String answer = "";
            String[] arr = s.split(""); // 문자열.split("") -> 문자열 하나씩 배열에 저장
            for(int j = 0; j < arr.length; j++){
                answer += arr[j].repeat(r); // 반복한문자.repeat(반복횟수)
            }
            System.out.println(answer);
        }
    }
}