package demo; import java.util.Scanner; public class check { public static void main(String[] args) { check no = new check(); no.output(); } private int input() { int n; Scanner sc = new Scanner(System.in); System.out.print("Nhap vao so gach: "); n = sc.nextInt(); return n; } private void output() { int n; n = input(); int chose; System.out.println("Cac cach co the xay duoc la: "); System.out.println("--------------------------------------"); for (int i = 1; i <= n; i++) { check(i, n); } System.out.println("--------------------------------------"); System.out.println("Nhap lua chon tiep theo: "); System.out.println("1. Tinh so khac: "); System.out.println("2. Thoat "); Scanner sc = new Scanner(System.in); chose = sc.nextInt(); switch (chose) { case 1: callback(); break; case 2: System.exit(1); break; } } private void callback() { output(); } private void check(int temp, int total) { int[] mang = new int[temp]; int i; for (i = 0; i < temp; i++) { mang[i] = 0; } calc(mang, total); for (i = temp - 1; i >= 0; i--) { if (mang[i] == 0) { mang[i] = 1; int j; for (j = i + 1; j < temp; j++) { mang[j] = 0; } calc(mang, total); i = temp; } } } public void calc(int[] a, int total) { int sum = 0; for (int i = 0; i < a.length; i++) { if (a[i] == 0) sum += 1; else sum += 2; } if (sum == total) { for (int j = 0; j < a.length; j++) { if (a[j] == 0) System.out.print("small "); else System.out.print("Big "); } System.out.println(); } } }