文章
2
粉丝
33
获赞
0
访问
805
import java.util.Scanner;
public class Main{
public static void main(String[] args){
int count = 0, index = 0, temp = 0;
int[] list;
try(Scanner scanner = new Scanner(System.in)){
list = new int[scanner.nextInt()];
for(int i = 0; i < list.length; i++){
list[i] = scanner.nextInt();
}
}
for(int i = 1; i <= list.length; i++){
for(int j = 0; j < list.length; j++){
if(list[j] == i){
index = j;
}
}
while(index != i - 1){
temp = list[index - 1];
list[index - 1] = i;
list[index] = temp;
count++;
index--;
}
}
System.out.print(count);
}
}
登录后发布评论
暂无评论,来抢沙发