public static void main(String[] args) throws Exception { FastScanner sc = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); int u = 1; while (u <= n) { String s = sc.next(); TreeSet<Long> set = new TreeSet<Long>(); set.add(Long.parseLong(s)); for (int i = 0; i < s.length(); i++) { for (int j = i + 1; j < s.length(); j++) { String next = s.substring(0, i) + s.charAt(j) + s.substring(i + 1, j) + s.charAt(i) + s.substring(j + 1); if (next.charAt(0) != '0') { set.add(Long.parseLong(next)); } } } min = set.first(); max = set.last(); out.println("Case #" + u + ": " + min + " " + max); u++; } out.close(); }
public void solve() throws IOException { /* MAIN CODE GOES HERE!!! */ MyQueueOnMyLinkedList q = new MyQueueOnMyLinkedList(); int n = in.nextInt(); for (int i = 0; i < n; i++) { String s = in.next(); if (s.charAt(0) == '-') { out.println(q.pop()); } else if (s.charAt(0) == '+') { q.push(in.nextInt()); } } }
public static void main(String[] args) throws Exception { FastScanner sc = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); out.println(getSubstrings(sc.next())); // int t = sc.nextInt(); // while (t > 0) { // t--; // int n = sc.nextInt(); // int k = sc.nextInt(); // int q = sc.nextInt(); // String s = sc.nextLine(); // while (q > 0) { // q--; // int left = sc.nextInt(); // int right = sc.nextInt(); // out.println(solve(s, k, left, right)); // } // } out.close(); }