import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int n, i, j;
int arr[] = new int [101];
int tmp = 0, cnt = 0;
n = scan.nextInt();
for (i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}
for (i = 1; i < n; i++) {
for (j = i; j > 0; j--) {
if (arr[j] < arr[j - 1]) {
tmp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = tmp;
cnt++;
}
else break;
}
}
System.out.printf("%d", cnt);
}
}
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=1087&sca=2070
'정올문제소스코드' 카테고리의 다른 글
2858 : 쇠막대기 (0) | 2021.12.05 |
---|---|
1221 : 후위표기법1 (0) | 2021.12.05 |
1157 : 버블정렬 (0) | 2021.12.05 |
1158 : 삽입정렬 (0) | 2021.12.05 |
1146 : 선택정렬 (0) | 2021.12.05 |