1.


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* Problem: 10327 Flip Sort
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1268
*
* @author Weigl Joseph
* @author Müller Thomas
* @version 1.0, 05/02/2011
*
* Status : Accepted
* Runtime: 0.508
*/


public class Main {


public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer token = new StringTokenizer("");
int n,
count;
BigInteger[] input;

while(reader.ready() || token.hasMoreElements()){
while(!token.hasMoreTokens() || token == null)
token = new StringTokenizer(reader.readLine());
n = Integer.parseInt(token.nextToken());
input = new BigInteger[n];
count = 0;
for(int i = 0; i < n; i++){
while(!token.hasMoreTokens()&& reader.ready())
token = new StringTokenizer(reader.readLine());
if(token.hasMoreTokens())
input[i] = new BigInteger(token.nextToken());
else
input[i] = input[i-1];
}
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
if(input[i].compareTo(input[j]) > 0)
count++;
}
}
System.out.println("Minimum exchange operations : " + count);
}

}


}


------------------------------------


1.
/**
 * 
 * Problem #10327 - Flip Sort
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1268

 * 
 * @author Mariya Vlaseva
 * 
 * Status : Accepted
 * Runtime: 0.672
 */
import java.util.Scanner;

public class Main {

private static final int MAX_NUMBERS_SIZE = 1000;

/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String result = "";
while(sc.hasNext()) {
int size = sc.nextInt();
if(checkInput(size)) {
int[] numbers = new int[size];
for(int i = 0; i < size; i++) {
numbers[i] = sc.nextInt();
}
result += bubbleSort(numbers) + " ";
}
}
sc.close();
printResult(result.trim());
}

private static void printResult(String result) {
for(String s : result.split(" ")) {
System.out.println("Minimum exchange operations : " + s);
}
}

private static int bubbleSort(int[] numbers) {
int exOps = 0;
boolean swap = true;
while(swap) {
swap = false;
for(int i = 0; i < numbers.length; i++) {
if(i+1 < numbers.length && numbers[i] > numbers[i+1]) {
int tmp = numbers[i];
numbers[i] = numbers[i+1];
numbers[i+1] = tmp;
exOps++;
swap = true;
}
}
}
return exOps;
}

private static boolean checkInput(int size) {
return size > 0 && size <= MAX_NUMBERS_SIZE;
}
}

2.

/**

* 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;

      }

}