https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PmkDKAOMDFAUq&categoryId=AV5PmkDKAOMDFAUq&categoryType=CODE

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

www.swexpertacademy.com

풀이

  1. 알파벳과 개수를 각각 char배열과 Int배열에 저장한다.
  2. 알파벳과 숫자 쌍의 개수(N)만큼 반복
    1. 각 알파벳의 숫자 만큼 알파벳을 출력한다.
    2. 출력을 10번할때마다 한 줄 띄어준다.
import java.io.*;
import java.util.StringTokenizer;

public class Solution {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1; tc<=T; tc++) {
        
			int n = Integer.parseInt(br.readLine());
			char[] c = new char[n]; //알파벳을 저장
			int[] num = new int[n]; // 알파벳 개수를 저장
			
            
			for(int i=0; i<n; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				c[i] = st.nextToken().charAt(0);
				num[i] = Integer.parseInt(st.nextToken());
			}
			
            
			System.out.println("#"+tc);
			int cnt=0; // 출력 횟수
			for(int i=0; i<n; i++) {
				for(int j=0; j<num[i]; j++) {
					System.out.print(c[i]);
					cnt++;
					if(cnt == 10) {
						System.out.println();
						cnt = 0;
					}
				}
				
			}
			System.out.println();
			
		}
	}

}

'SWEA > D2' 카테고리의 다른 글

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

+ Recent posts