[SWEA] 의석이의 세로로 말해요 Posted on 2020-01-19 | In Problem_Solving | 문제 보러가기 제한사항 이외의 제한사항은 없다. 첫번째 생각 2차원 배열로 칠판을 관리하고, 공백만 체크해서 예외처리를 해주는 방식으로 해결하였다. Code 12345678910111213141516171819202122232425262728293031323334353637383940414243import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int tc = 1; tc <= T; tc++) { StringBuffer sb = new StringBuffer(); String s[] = new String[5]; char b[][] = new char[5][]; int len = 0; for (int i = 0; i < 5; i++) { s[i] = sc.next(); b[i] = new char[s[i].length()]; for (int j = 0; j < b[i].length; j++) { b[i][j] = s[i].charAt(j); if (len < s[i].length()) len = s[i].length(); } } char a[][] = new char[len][len]; for (int i = 0; i < 5; i++) { for (int j = 0; j < len; j++) { if (b[i].length <= j) break; a[i][j] = b[i][j]; } } for (int i = 0; i < len; i++) for (int j = 0; j < 5; j++) { if(a[j][i] != 'import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int tc = 1; tc <= T; tc++) { StringBuffer sb = new StringBuffer(); String s[] = new String[5]; char b[][] = new char[5][]; int len = 0; for (int i = 0; i < 5; i++) { s[i] = sc.next(); b[i] = new char[s[i].length()]; for (int j = 0; j < b[i].length; j++) { b[i][j] = s[i].charAt(j); if (len < s[i].length()) len = s[i].length(); } } char a[][] = new char[len][len]; for (int i = 0; i < 5; i++) { for (int j = 0; j < len; j++) { if (b[i].length <= j) break; a[i][j] = b[i][j]; } } for (int i = 0; i < len; i++) for (int j = 0; j < 5; j++) { if(a[j][i] != '\0') { sb.append(a[j][i]); } } System.out.println("#" + tc + " " + sb.toString()); } } } ') { sb.append(a[j][i]); } } System.out.println("#" + tc + " " + sb.toString()); } } }