728x90
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
// attribute
static String[] array;
static boolean[] check;
static ArrayList<String> ans;
public static void main(String[] args) {
try {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(bf.readLine()); // ๋ถ๋ฑํธ ๊ฐ์
array = new String[a]; // ๋ถ๋ฑํธ
array = bf.readLine().split(" ");
check = new boolean[10];
ans = new ArrayList<String>();
dfs("", 0, a); // index, a
System.out.println(ans.get(ans.size()-1));
System.out.println(ans.get(0));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void dfs(String string, int index, int a) {
if(index == a + 1) { // ์ธ๋ฑ์ค๊ฐ ๋ถ๋ฑํธ ๊ฐ์ + 1์ ๋ง์กฑ
ans.add(string);
return;
}else {
for (int i = 0; i < 10; i++) {
if(check[i]) continue;
if(index == 0 || compare(string.charAt(string.length()-1) - '0', i, index)) {
check[i] = true;
dfs(string+i, index+1, a);
check[i] = false;
}
}
}
}
private static boolean compare(int a, int i, int index) {
if(array[index-1].equals(">")) return a>i;
else return a<i;
}
}
728x90
'PS > BaekJoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
1002 JAVA ํฐ๋ (0) | 2023.01.01 |
---|---|
10974 JAVA ๋ชจ๋ ์์ด (0) | 2022.10.27 |
10819 JAVA ์ฐจ์ด๋ฅผ ์ต๋๋ก (0) | 2022.10.26 |
1259 JAVA ํฐ๋ฆฐ๋๋กฌ์ (0) | 2022.08.31 |
10828 JAVA ์คํ (0) | 2022.08.30 |