蓝桥杯 练习系统 算法提高答案Java

2026/4/23 5:42:40

Collections.sort(list);

int n=list.get(list.size()-1)-list.get(0);

if(n==2) { System.out.println(\ System.out.println(n); }

else if(n==0 || n==1) { System.out.println(\ System.out.println(0); } else {

for(int i=2;i

}

}

ADV-131 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.nextLine()); String[] str=sc.nextLine().split(\ int[] array=new int[str.length]; for(int i=0;i

选择排序

}

array[i]=Integer.parseInt(str[i]); } stepChoiceSort(array, 0); }

public static void stepChoiceSort(int[] array,int index){ if(index>=array.length){ return; }else{ int min=index; for(int i=min+1;i

public static String xunhuan(int[] a){ String str=\ for(int i=0;i

ADV-130 色盲的民主

import java.util.Scanner;

public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String[] colors = new String[n]; for (int i = 0; i < n; i++) { colors[i] = sc.nextLine();

} int[] sum = new int[n]; for (int i = 0; i < n; i++) { int count = 0; for (int j = i + 1; j < n; j++) { if (colors[i].equals(colors[j])) { count++; } } sum[i] = count; } int max = sum[0]; for (int i = 1; i < n; i++) { if (max < sum[i]) { max = sum[i]; } } String[] t = new String[n]; int m = 0; for (int i = 0; i < n; i++) { if (sum[i] == max) { t[m] = colors[i]; m++; } } int tLen=0; for (int i = 0; i < n; i++) { if (t[i] != null) { tLen++; } } for (int i = 0; i < tLen; i++) { for (int j = i + 1; j < tLen; j++) { int len = t[i].length() > t[j].length() ? t[j].length() : t[i] .length(); for (int k = 0; k < len; k++) { if (t[i].charAt(k) > t[j].charAt(k)) { String s = t[i]; t[i] = t[j]; t[j] = s;

}

}

break; } if (t[i].charAt(k) < t[j].charAt(k)) { break; } } } }

for (int i = 0; i

ADV-129 插入排序

import java.util.ArrayList; import java.util.List; import java.util.Scanner;

public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] nums=new int[n]; int i=0; while(i list=new ArrayList(); for(i=0;i1){ for(int j=list.size()-1;j>=0;j--){ if(j>0){ if(list.get(j-1)>value){


蓝桥杯 练习系统 算法提高答案Java.doc 将本文的Word文档下载到电脑
搜索更多关于: 蓝桥杯 练习系统 算法提高答案Java 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219