Skip to content

week 16 #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
week 16
  • Loading branch information
jdalma committed Aug 9, 2022
commit cd462022dfabb4f9092f760640467ca2446ad64a
53 changes: 53 additions & 0 deletions [Week16 - Recursion&Backtracking]/정현준/A_2529.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
static char[] chars;
static int size;
static boolean[] check;
static List<String> results;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

size = Integer.parseInt(br.readLine());
chars = new char[size];
String line = br.readLine().replace(" ", "");
for (int i = 0; i < size; i++) {
chars[i] = line.charAt(i);
}
check = new boolean[10];
results = new ArrayList<>();

find(0, "");
Collections.sort(results);
System.out.println(results.get(results.size() - 1));
System.out.println(results.get(0));
}

public static void find(int count, String number) {
if (count == size + 1) {
results.add(number);
return;
}
for (int i = 0; i <= 9; i++) {
if (check[i])
continue;
if (count == 0 || compare(number.charAt(count - 1) - '0', i, chars[count - 1])) {
check[i] = true;
find(count + 1, number + i);
check[i] = false;
}
}
}

public static boolean compare(int num1, int num2, char ch) {
if (ch == '>') {
return num1 > num2;
}
return num1 < num2;
}

}
Empty file.