第二题是真的没想明白
第三题我猜是无限循环问题我没解决(懒了感觉差不多就行了就没继续搞)
####第一题:第一行输入一个数组,第二行输入两个整数i,len。从第i个整数开始输出len个数。如果数组超了,那就只输出到末尾。输出的时候,每二十个需要换行,每个输出用;隔开
####第三题:输入多个结构体语句和一个sizeof语句,得到结构体大小。如果某个结构体出现未声明变量,则返回0。这题递归会溢出,需要优化
####第二题:一共n个司机,输入四行,每行n个数。第一行输入距离,第二行输入阻塞距离,第三行输入红绿灯个数,第四行输入评分。普通距离速度10m/s,堵塞距离2m/s,红绿灯每个有50%概率等待15s。求得最短时间t的司机m。如果有司机评分高并且耗时t2<t+60,那么选评分高的司机。注意:普通距离要减去堵塞距离
>代码不是最终结果,提交的有小改动
//3 import java.util.*; class test{ public static void main(String[] args){ Scanner in = new Scanner(System.in); HashMap<String, String> map = new HashMap<>(); int flag = 0; String name = ""; String member = ""; String s = ""; while(in.hasNext()){ s = in.nextLine(); if (flag == 0){ name = s.substring(7, s.length() - 2); flag = 1; }else if (s.equals("}")){ flag = 0; map.put(name, member); member = ""; }else{ member += s; member += "*"; } } //System.out.println(s.substring(8, s.length() -1)); System.out.println(size(s.substring(8, s.length() -1), map)); } private static int size(String s, HashMap<String, String> map){ String m = map.get(s); //System.out.println(m.substring(0, m.length() - 1)); String[] arr = m.substring(0, m.length() - 1).split("\\*"); int res = 0; for (int i = 0; i < arr.length; i++){ String temp = arr[i]; //System.out.println(temp.substring(4, 8)); if (temp.substring(4, 8).equals("char")){ res += 1; }else if (temp.substring(4, 8).equals("shor")){ res += 2; }else if (temp.substring(4, 8).equals("long")){ res += 4; }else { //System.out.println(temp.split(" ")[1]); //System.out.println(temp.substring(4)); res += size(temp.substring(4).split(" ")[1], map); } } return res; } } ---------------------------------------------------------------------------------------------------------------------- //1 import java.util.*; class test{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ String s = in.nextLine(); int n = in.nextInt(); int len = in.nextInt(); helper(s, n, Math.min(n + len, s.length())); } } private static void helper(String s, int n, int len){ int k = 0; String res = ""; for (int i = n; i < len; i++){ res += s.charAt(i); res += ";"; k++; if (k == 20){ System.out.println(res); res = ""; k = 0; } } if (!res.equals("")){ System.out.println(res); } } } ------------------------------------------------------------------------------------------------------------- //2 (第二题代码缺的比较多,主要是才44就不补出来了) import java.util.*; class test{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ String s1 = in.nextLine(); String s2 = in.nextLine(); String s3 = in.nextLine(); String s4 = in.nextLine(); String[] arr1 = s1.split(" "); String[] arr2 = s2.split(" "); String[] arr3 = s3.split(" "); String[] arr4 = s4.split(" "); double[] time = new double[arr1.length]; for (int i = 0; i < time.length; i++){ time[i] = helper(Integer.valueOf(arr1[i]), Integer.valueOf(arr2[i]), Integer.valueOf(arr3[i])); } System.out.println(time[0]); } } private static double helper(int a, int b, int c){ double time = (double)(a - b) / 10 + (double)b / 2 + (double)c * 15 / 2; return time; } }今天通知笔试过了,希望面试好运,求收留!
全部评论
(12) 回帖