[头条笔试]坐标的题目怎么做?
本地测试通过,但是赛码网是0%,然后就较劲了,觉得不可能,甚至还用赛码网的其他在线编程题做测试,输入题目条件中的样例,也可以得到题目中的样例输出,真心求解,哭😢
import java.util.*; public class Main { class Point{ private int x; private int y; public int getX(){ return x; } public int getY(){ return y; } public Point(int x, int y){ this.x = x; this.y = y; } } public void process(){ Scanner scanner=new Scanner(System.in); List points = new ArrayList(); while(scanner.hasNextLine()){ int total = scanner.nextInt(); for(int i = 0; i< total; i++){ String[] pointstr = scanner.nextLine().split(" "); int x = Integer.parseInt(pointstr[0]); int y = Integer.parseInt(pointstr[1]); points.add(new Point(x,y)); } List resultPoints = new ArrayList(); for(int j = 0; j<points.size(); j++){ Point currentPoint = points.get(j); Boolean flag = true; for(int k = 0; k<points.size(); k++){ if(points.get(k).getX() > currentPoint.getX() && points.get(k).getY() > currentPoint.getY()){ flag = false; break; } } if(flag) {resultPoints.add(currentPoint);} } Collections.sort(resultPoints, new Comparator(){ public int compare(Point o1, Point o2) { return Integer.compare(o1.getX(), o2.getX()); } }); for(int m = 0; m<resultPoints.size(); m++){ System.out.print(resultPoints.get(m).getX()); System.out.print(" "); System.out.print(resultPoints.get(m).getY()); System.out.println(""); } } } public static void main(String[] args) { Main m = new Main(); m.process(); } }#字节跳动#