java写的,只有60分,求dl指点
查看原帖
java写的,只有60分,求dl指点
1444408
AnPotato楼主2024/9/13 23:18
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 23:18
加载中...