Esempio n. 1
0
 /**
  * Reads a sequence of integers from standard input and
  * prints the number of inversions to standard output.
  *
  * @param args the command-line arguments
  */
 public static void main(String[] args) {
     int[] a = StdIn.readAllInts();
     int n = a.length;
     Integer[] b = new Integer[n];
     for (int i = 0; i < n; i++)
         b[i] = a[i];
     StdOut.println(Inversions.count(a));
     StdOut.println(Inversions.count(b));
 }
Esempio n. 2
0
    /**
     * Reads in a sequence of extended ASCII strings or non-negative ints from standard input;
     * American flag sorts them;
     * and prints them to standard output in ascending order.
     *
     * @param args the command-line arguments: "int" to read input as non-negative integers
     */
    public static void main(String[] args) {
        if (args.length > 0 && args[0].equals("int")) {
            int[] a = StdIn.readAllInts();
            sort(a);

            // print results
            for (int i = 0; i < a.length; i++)
                StdOut.println(a[i]);
        }

        else {
            String[] a = StdIn.readAllStrings();
            sort(a);
            // print results
            for (int i = 0; i < a.length; i++)
                StdOut.println(a[i]);
        }
    }