全部评论
通过的人是怎么输出的,我是完全按照输出样例,加了中括号,引号,逗号,空格,还是过不了
大佬a了几道?
第二题写着写着头晕了,代码写的又臭又长只过了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] + "\',");
}
}
}
}
哎,始终给你说输出合适不对
主要是空格,加上空格就A了
相关推荐