정올-Beginner-재귀-주사위던지기1

Titanium·2025년 3월 7일

JUNGOL

목록 보기
2/3
post-thumbnail
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        char[][] a = new char[n][n];
        char c = 'A';

        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < n; j++) {
                    a[j][i] = c;
                    c = (c == 'Z') ? 'A' : (char) (c + 1);
                }
            } else {
                for (int j = n - 1; j >= 0; j--) {
                    a[j][i] = c;
                    c = (c == 'Z') ? 'A' : (char) (c + 1);
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        for (char[] r : a) {
            for (char x : r) sb.append(x).append(" ");
            sb.append("\n");
        }
        System.out.print(sb);
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        char[][] a = new char[n][n];
        char c = 'A';

        for (int i = 0; i < n; i++) {
            int start = (i % 2 == 0) ? 0 : n - 1;
            int step = (i % 2 == 0) ? 1 : -1;
            for (int j = 0; j < n; j++) {
                a[start + j * step][i] = c;
                c = (c == 'Z') ? 'A' : (char) (c + 1);
            }
        }

        StringBuilder sb = new StringBuilder();
        for (char[] r : a) {
            for (char x : r) sb.append(x).append(" ");
            sb.append("\n");
        }
        System.out.print(sb);
    }
}
profile
핵심먼저

0개의 댓글