java写的,只有六十分,求大佬指点
  • 板块题目总版
  • 楼主AnPotato
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/9/13 18:41
  • 上次更新2024/9/13 21:46:32
查看原帖
java写的,只有六十分,求大佬指点
1444408
AnPotato楼主2024/9/13 18:41
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 1;
        volunteer[] v = new volunteer[n];
        for (int i = 0;i < v.length;i++){
            int t = sc.nextInt();
            int k = sc.nextInt();
            v[i] = new volunteer(count,t,k,t*k);
            count++;
        }
        Arrays.sort(v);
        for(int i = 0;i < v.length;i++){
            System.out.print(v[i].id+" ");
        }
    }
}

class volunteer implements Comparable<volunteer> {
    int id;
    int time;
    int k;
    int value;

    public volunteer(int id, int time, int k, int value) {
        this.id = id;
        this.time = time;
        this.k = k;
        this.value = value;
    }

    @Override
    public int compareTo(volunteer o) {
        return o.value - this.value;
    }
}
2024/9/13 18:41
加载中...