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

发布时间 : 星期四 文章蓝桥杯 练习系统 算法提高答案Java更新完毕开始阅读

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){

联系合同范文客服:xxxxx#qq.com(#替换为@)