First, solve the problem. Then, write the code. ” - John Johnson

It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas

Wednesday, July 16, 2014

Flip Sort.

Author : Jisan
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-10327
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1268

Code:

import java.util.*;
public class Uva_10327 {
    public static void main(String args[]){
    Scanner input=new Scanner(System.in);
    while(input.hasNext()){
    int a=input.nextInt();
    int[] tomato=new int[a];
    for(int b=0;b<tomato.length;b++){
    tomato[b]=input.nextInt();
    }
    int count=flipSort(tomato);
    System.out.println("Minimum exchange operations : "+ count);
    }
    }
    public static int flipSort(int[] A){
    int s=0;
    for(int i=0;i<A.length-1;i++){
    for(int j=i+1;j<A.length;j++){
    if(A[i]>A[j]){
    s++;
    }
    }
    }
    return s;
    }
}

No comments:

Post a Comment