8月24日中兴笔试-AK代码
题目难度不大,输入输出很恶心
为了部落
模版题:经典求最短路径 Dijkstra
public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNextLine()){ String line = input.nextLine(); String[] arr = line.substring(1, line.length() - 1).split(","); int n = Integer.parseInt(input.nextLine()); int k = Integer.parseInt(input.nextLine()) - 1; List<int[]>[] adj = new List[n]; for(int i = 0; i < n; ++i) adj[i] = new ArrayList<>(); for(int i = 0; i < arr.length; i += 3){ int from = Integer.parseInt(arr[i].substring(1)) - 1, to = Integer.parseInt(arr[i + 1]) - 1, cost = Integer.parseInt(arr[i + 2].substring(0, arr[i + 2].length() - 1)); adj[from].add(new int[]{to, cost}); } int[] ans = getDistince(k, adj, n); int res = 0; for(int num : ans) res = Math.max(num, res); System.out.println(res == Integer.MAX_VALUE / 2 ? -1 : res); } } static int[] getDistince(int start, List<int[]>[] adj, int n){ int[] ans = new int[n]; Arrays.fill(ans, Integer.MAX_VALUE / 2); ans[start] = 0; Queue<Integer> queue = new ArrayDeque<>(); queue.offer(start); while (!queue.isEmpty()){ int a = queue.poll(); for(int[] temp : adj[a]){ int b = temp[0], bCost = temp[1]; if(ans[a] + bCost < ans[b]){ ans[b] = ans[a] + bCost; queue.offer(b); } } } return ans; }
新农村
遍历就完事了
public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNextLine()){ String[] line = input.nextLine().split(" "); char startChar = line[0].charAt(0), endChar = line[1].charAt(0); int startNum = Integer.parseInt(line[0].substring(1)), endNum = Integer.parseInt(line[1].substring(1)); List<String> list = new ArrayList<>(); if(startChar <= endChar && startNum <= endNum){ while (startChar <= endChar){ int num = startNum; while (num <= endNum){ list.add(startChar+""+num); ++num; } startChar++; } } System.out.println(list); } }#中兴##笔试##2023校招#