본문 바로가기
알고리즘 문제풀이/백준

[알고리즘/백준] 2675 문자열 반복(자바)

by jeonghaemin 2021. 9. 19.
728x90

문제

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

풀이 코드

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < t; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int r = Integer.parseInt(st.nextToken());
            String s = st.nextToken();

            for (char c : s.toCharArray()) {
                for (int j = 0; j < r; j++) {
                    sb.append(c);
                }
            }
            sb.append("\n");
        }

        System.out.println(sb);
    }
}

댓글