1. 

/**

* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10

 * Problem: 10327 - Flip Sort

* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1268

*

 * @author Viktoriya Ryabova

* @version 1.0, 05/22/2010

*

 * Method : Ad-Hoc

* Status : Accepted

* Runtime: 0.624

*/

 

import java.util.Scanner;

public class Main {

 

     

      public static void main(String[] args) {

            // TODO Auto-generated method stub

            Scanner sc = new Scanner (System.in);

            while (sc.hasNext()) {

 

                  int count = sc.nextInt();

                  if (count<=1000){

                  int[] numbers = new int[count];

                  //zahlen werden aus der kosnole in das array hinzugefuegt

                  for (int i = 0; i < count; i++) {

                        numbers[i] = sc.nextInt();

                  }

                  int swaps = sortiere(numbers);

                  System.out.println("Minimum exchange operations : "+swaps);

                  }

            }

      }

      public static int sortiere(int[] x) {

            int swaps = 0;

            boolean unsortiert=true;

            int temp;

           

            while (unsortiert){

               unsortiert = false;

               for (int i=0; i < x.length-1; i++)

                   //neben stehende zahlen werden verglichen

                   //falls vorgehende zahl groesser ist, als nachkommende, werden die getauscht und

                   // count nach oben gezaehlt

                  if (x[i] > x[i+1]) {                     

                     temp       = x[i];

                     x[i]       = x[i+1];

                     x[i+1]     = temp;

                     swaps++;

                     unsortiert = true;

                  }         

            }

            return swaps;

      }

}