第二题写着写着头晕了,代码写的又臭又长只过了66.7,bug巨多。。。剩下三道都a了 第三题 import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class ByteDance3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input = sc.nextLine(); String[] strs = input.split(" "); int[][] nums = new int[strs.length][2]; for (int i = 0; i < strs.length; i++) { nums[i][0] = Integer.parseInt(strs[i]); nums[i][1] = i; } Arrays.sort(nums, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { if (o1[0] - o2[0] == 0) { return o1[1] - o2[1]; }else { return o2[0] - o1[0]; } } }); String[] res = new String[strs.length]; for (int i = 0; i < strs.length; i++) { int index = nums[i][1]; if (i == 0) { res[index] = "金"; }else if (i == 1) { res[index] = "银"; }else if (i == 2) { res[index] = "铜"; }else { res[index] = (i + 1) + ""; } } for (int i = 0; i < res.length; i++) { if (i == 0) { System.out.print("[\'" + res[i] + "\',"); }else if (i == res.length - 1) { System.out.print(" \'" + res[i] + "\']"); }else { System.out.print(" \'" + res[i] + "\',"); } } } }
点赞 1

相关推荐

不愿透露姓名的神秘牛友
06-25 19:15
点赞 评论 收藏
分享
点赞 评论 收藏
分享
墨西哥大灰狼:如果你的校友卤馆还在的话,他肯定会给你建议的,可是卤馆注销了@ 程序员卤馆
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务