SWEA/D2
[SWEA] 1946. 간단한 압축 풀기
둘기친구
2019. 5. 14. 01:58
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
www.swexpertacademy.com
풀이
- 알파벳과 개수를 각각 char배열과 Int배열에 저장한다.
- 알파벳과 숫자 쌍의 개수(N)만큼 반복
- 각 알파벳의 숫자 만큼 알파벳을 출력한다.
- 출력을 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(); } } }