电信JAVA三题
选择题一路不会,20多分钟点完。
编程题有点简单,20多分钟敲完。
一共做了45分钟。。
第一题
import java.util.Arrays; import java.util.Scanner; public class p1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] array = new int[n]; for(int i = 0; i < n; i++){ array[i] = input.nextInt(); } Arrays.sort(array); int res = 0; if(n % 2 == 0){ res = array[n/2 - 1]; }else{ res = array[(n - 1)/2]; } System.out.println(res); } }第二题
import java.util.Scanner; public class p2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num = input.nextInt(); int[] value = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; String[] str = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; StringBuilder res = new StringBuilder(); for(int i = 0; i < value.length; i++){ while(num >= value[i]){ num -= value[i]; res.append(str[i]); } } System.out.println(res.toString()); } }第三题
import java.util.Scanner; public class p3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String str = input.nextLine(); String newstr = str.substring(1, str.length() - 1); String[] a = newstr.split(", "); int n = a.length; int[] array = new int[n]; for(int i = 0; i < n; i++){ array[i] = Integer.parseInt(a[i]); } int start = array[0]; int max = array[0]; for (int i = 1; i < n; i++){ start = Math.max(start + array[i], array[i]); max = Math.max(start, max); } System.out.println(max); } }