AcWing 862. 三元组排序 - Java
原题链接
简单
作者:
KYCygni
,
2021-04-04 07:25:12
,
所有人可见
,
阅读 539
Java 代码
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Collections;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
List<Data> l = new ArrayList<Data>();
for (int i = 0; i < n; i ++)
{
Data d = new Data(cin.nextInt(), cin.nextDouble(), cin.nextLine());
l.add(d);
}
Collections.sort(l, new Data());
for (int i = 0; i < l.size();i++)
{
System.out.println(l.get(i));
}
}
static class Data implements Comparator<Data>
{
int x = 0;
double y = 0.0;
String z = "";
public Data()
{
}
public Data (int x1, double y1, String z1)
{
x = x1;
y = y1;
z = z1;
}
public int getX()
{
return x;
}
public String toString()
{
return x + " " + String.format("%.2f", y) + z;
}
public int compare(Data obj1, Data obj2)
{
return obj1.getX() - obj2.getX();
}
}
}