Baekjoon Algorithm | Problem 2675: String Repetition

Source

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

Problem

Solve Baekjoon Online Judge problem 2675, String Repetition.

Input

Follow the input format and constraints given in the original problem statement.

Output

Print the answer required by the problem.

Sample Input 1

2 3 ABC 5 /HTP

Sample Output 1

AAABBBCCC /////HHHHHTTTTTPPPPP

Algorithm Classification

  • Implementation
  • String

Solution

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        ) {
            int n = Integer.parseInt(br.readLine());

            for (int i = 0; i < n; i++) {
                String[] input = br.readLine().split(" ");
                final int r = Integer.parseInt(input[0]);
                final String s = input[1];

                for (int j = 0; j < s.length(); j++) {
                    for (int x = 0; x < r; x++) {
                        bw.write(s.charAt(j));
                    }
                }
                bw.write("\n");
            }

            bw.flush();
        }
    }
}