PLOD

[백준] 세로읽기(10798) 본문

대외 활동 및 IT 지식/알고리즘 문제 풀이 정리

[백준] 세로읽기(10798)

훌룽이 2026. 2. 18. 11:25

https://www.acmicpc.net/problem/10798

✅ 코드

package test;

import java.io.*;
import java.util.*;

public class 백준_10798 {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int max = 0;
        char[][] arr = new char[5][15];

        for(int i = 0; i < 5 ; i++){
            String str = br.readLine();

            if(str.length() > max){
                max = str.length();
            }

            for(int j = 0; j < str.length(); j++){
                arr[i][j] = str.charAt(j);
            }

        }

        for(int i = 0; i < max ; i++){
            for(int j = 0; j < 5 ; j++){
                if(arr[j][i] == '\0'){
                    continue;
                }
                System.out.print(arr[j][i]);
            }
        }
    }
}

// 14272	104

💡 배운 점 & 느낀 점

  1. str.charAt(j) → String 문자열에서 인덱스 j번째 출력
  2. arr[j][i] == '\0' →  
char[][] arr = new char[5][15];

다음과 같이 초기화 했을 때, char 형태의 배열은 '\0'으로 초기화

Comments