1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); char[][] cWord = new char[5][15]; int max = 0; // 입력받는 문자열 중 가장 긴 문자열의 길이 for(int i=0; i<5; i++) { String str = scan.next(); max = Math.max(max, str.length()); // 가장 긴 문자열 체크 for(int j=0; j<str.length(); j++) cWord[i][j] = str.charAt(j); } for(int i=0; i<max; i++) { for(int j=0; j<5; j++) { if(cWord[j][i] == '\0') // char 배열의 초깃값 = '\0' continue; System.out.print(cWord[j][i]); } } scan.close(); } } | cs |
이차원 배열을 활용해야 한다
'Algorithm' 카테고리의 다른 글
백준 10870 피보나치 수열 with JAVA (0) | 2023.12.29 |
---|---|
백준 2720 세탁소 사장 동혁 (0) | 2023.08.29 |
백준 2563 색종이 (0) | 2023.08.28 |
백준 단어 공부 1157 (0) | 2023.08.28 |
백준 10988 팰린드롬인지 (0) | 2023.08.28 |