- 문제풀이
import java.util.Scanner;
public class Main {
static int[][] table;
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] nums = sc.nextLine().split(" ");
int n = Integer.parseInt(nums[0]);
int type = Integer.parseInt(nums[1]);
table = new int[n][n];
table[0][0] = 1;
for(int i = 1 ; i < n ; i++) {
for(int j = 0 ; j < n ; j++) {
table[i][j] = table[i - 1][j];
if(j != 0) {
table[i][j] += table[i - 1][j-1];
}
}
}
switch(type) {
case 1: type1(n); break;
case 2: type2(n); break;
case 3: type3(n); break;
}
System.out.println(sb.toString());
}
public static void type1(int n) {
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j <= i ; j++) {
sb.append(table[i][j]).append(" ");
}
sb.append("\n");
}
}
public static void type2(int n) {
for(int i = n - 1 ; i > -1 ; i--) {
for(int j = 0 ; j < n - i - 1 ; j++) {
sb.append(" ");
}
for (int j = 0 ; j <= i ; j++) {
sb.append(table[i][j]).append(' ');
}
sb.append('\n');
}
}
public static void type3(int n) {
for (int i = n - 1 ; i > -1 ; i--) {
for (int j = n - 1 ; j >= i ; j--) {
sb.append(table[j][i]).append(' ');
}
sb.append('\n');
}
}
}