Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.TreeSet;
- public class VariationsBrute {
- public static void main(String args[]) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int number = Integer.parseInt(br.readLine());
- String inp = br.readLine();
- inp = inp.replace(" ", "");
- brute(inp, number, new StringBuffer());
- tSet.forEach(System.out::println);
- }
- static TreeSet tSet = new TreeSet();
- static void brute(String input, int depth, StringBuffer output) {
- if (depth == 0) {
- tSet.add(output.toString());
- } else {
- for (int i = 0; i < input.length(); i++) {
- output.append(input.charAt(i));
- brute(input, depth - 1, output);
- output.deleteCharAt(output.length() - 1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement