본문 바로가기
Java/SW Expert Academy

1946. 간단한 압축 풀기

by GLOWWW 2021. 1. 11.
package oSWExpertAcademy;

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

public class D2_1946 {
    public static void main(String[]args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int testCase = Integer.parseInt(br.readLine());
            for(int tc=1; tc<=testCase; tc++) {
                int pair = Integer.parseInt(br.readLine());
                String[] eng = new String[pair];
                int[] num = new int[pair];
                for(int i=0; i<pair; i++) {
                    StringTokenizer st = new StringTokenizer(br.readLine());
                    eng[i] = st.nextToken();
                    num[i] = Integer.parseInt(st.nextToken());
                }
                System.out.println("#"+tc);
                //하나의 행에 10글자씩 담기위해 count를 만들어 초기화 시켜준다 
                int count = 0;
                for(int i=0; i<pair; i++) {
                    for(int j=0; j<num[i]; j++) {
                        System.out.print(eng[i]);
                        count++;
                        //count가 하나씩 추가되며 10이 되면 행을 바꿔준다 
                        if(count == 10) {
                            System.out.println();
                            count = 0;
                        }
                    }
                }
                System.out.println();
            }//testCase for문
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

'Java > SW Expert Academy' 카테고리의 다른 글

1940. 가랏! RC카!  (0) 2021.01.11
1945. 간단한 소인수분해  (0) 2021.01.11
1948. 날짜 계산기  (0) 2021.01.11
1954. 달팽이 숫자  (0) 2021.01.11
1959. 두 개의 숫자열  (0) 2021.01.09

댓글