본문 바로가기
Baekjoon Online Judge

[BOJ] 백준 2675번: 문자열 반복 (Java)

by 프로그래 밍구 2023. 3. 20.

문제링크

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

 

2675번: 문자열 반복

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

www.acmicpc.net


나의코드

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        
        for(int i = 0; i < n; i++){
            String[] str = br.readLine().split(" ");
            
            int num = Integer.parseInt(str[0]);
            String word = str[1];
            
            for(int j = 0; j < word.length(); j++){
                for(int k = 0; k < num; k++){
                    System.out.print(word.charAt(j));
                }
            }
            System.out.println();
        }                       
    }
}

 

댓글