์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step7] 2675 : ๋ฌธ์ž์—ด ๋ฐ˜๋ณต (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 11. 14:09

www.acmicpc.net/problem/2675

 

2675๋ฒˆ: ๋ฌธ์ž์—ด ๋ฐ˜๋ณต

๋ฌธ์ž์—ด S๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ํ›„์—, ๊ฐ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•ด ์ƒˆ ๋ฌธ์ž์—ด P๋ฅผ ๋งŒ๋“  ํ›„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ฆ‰, ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•˜๊ณ , ๋‘ ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•˜๋Š” ์‹์œผ๋กœ P๋ฅผ ๋งŒ๋“ค๋ฉด ๋œ๋‹ค

www.acmicpc.net


๋ฌธ์ œ

๋ฌธ์ž์—ด S๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ํ›„์—, ๊ฐ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•ด ์ƒˆ ๋ฌธ์ž์—ด P๋ฅผ ๋งŒ๋“  ํ›„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ฆ‰, ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•˜๊ณ , ๋‘ ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•˜๋Š” ์‹์œผ๋กœ P๋ฅผ ๋งŒ๋“ค๋ฉด ๋œ๋‹ค. S์—๋Š” QR Code "alphanumeric" ๋ฌธ์ž๋งŒ ๋“ค์–ด์žˆ๋‹ค.

QR Code "alphanumeric" ๋ฌธ์ž๋Š” 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\$%*+-./: ์ด๋‹ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T(1 ≤ T ≤ 1,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ๋ฐ˜๋ณต ํšŸ์ˆ˜ R(1 ≤ R ≤ 8), ๋ฌธ์ž์—ด S๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์ฃผ์–ด์ง„๋‹ค. S์˜ ๊ธธ์ด๋Š” ์ ์–ด๋„ 1์ด๋ฉฐ, 20๊ธ€์ž๋ฅผ ๋„˜์ง€ ์•Š๋Š”๋‹ค. 

 

์ถœ๋ ฅ

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์— ๋Œ€ํ•ด P๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

2

3 ABC

5 /HTP

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

AAABBBCCC

/////HHHHHTTTTTPPPPP


ํ’€์ด

1. ํ…Œ์ŠคํŠธ์ผ€์ด์Šค ๊ฐœ์ˆ˜ num์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

2. ๋ฐ˜๋ณต ํšŸ์ˆ˜๋ฅผ r์—, ๋ฐ˜๋ณตํ•  ๋ฌธ์ž๋ฅผ s์— ์ €์žฅํ•œ๋‹ค.

3. s์˜ ๊ธธ์ด๋งŒํผ ๊ฐ ๋ฌธ์ž๋ฅผ r๋ฒˆ ๋ฐ˜๋ณตํ•œ๋‹ค.

 

import java.io.*;
import java.util.StringTokenizer;

public class B2675 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		int num = Integer.parseInt(br.readLine()); // ํ…Œ์ŠคํŠธ์ผ€์ด์Šค ๊ฐœ์ˆ˜
		
		for(int i = 0; i < num; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int r = Integer.parseInt(st.nextToken()); // ๋ฐ˜๋ณตํ•  ํšŸ์ˆ˜ r
			String s = st.nextToken(); // ๋ฐ˜๋ณตํ•  ๋ฌธ์ž s

			for(int j = 0; j < s.length(); j++) { // s์˜ ๊ธธ์ด๋งŒํผ ์ˆ˜ํ–‰
				for(int k = 0; k < r; k++) { // s๋ฅผ ํ•˜๋‚˜์”ฉ ์ž˜๋ผ์„œ r๋งŒํผ ๋ฒ„ํผ์— ์ž…๋ ฅํ•ด์คŒ
					bw.write(s.charAt(j));
				}
			}
			bw.newLine(); // s ์ž…๋ ฅ ํ›„์— ๊ฐœํ–‰
		}
		bw.flush();
		bw.close();
	}

}