Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ccc5s2 {
- public static void main(String[] args) {
- Scanner sc= new Scanner(System.in);
- // compare with neighbor and see if A[i]<A[i+1]
- // 2 1 3
- // 2 3 1
- // 3 2 1
- int count = 0;
- int N = sc.nextInt();
- int[] A = new int[N];
- while (true) { //repeat multiple times
- boolean isSwap = false; //never swap yet
- for (int i=1; i<N; i++) {
- if (A[i-1]<A[i]) {
- //swap
- int temp = A[i];
- A[i] = A[i-1];
- A[i-1] = temp;
- count++;
- isSwap = true;
- }
- }
- if (isSwap==false) {
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement