2.5蓝桥杯打卡aaaaajava

1.n数累加

``````import java.util.Scanner;
import java.util.Arrays;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);

//在此输入您的代码...
int n = scan.nextInt();
int[] a = new int[n];
for(int i = 0;i < n; i++){
a[i] = scan.nextInt();
}
Arrays.sort(a);
int res = 0;
int sum = a[0];
for(int i = 0;i < n - 1;i++){
sum+=a[i + 1];
res+=sum;
}
System.out.println(res);
scan.close();
}
}

``````

2.接金币

``````package com.mvc.domain;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
* @author: 屠一乐
* @date: 2023/2/5 23:27
* @description:
*/
public class Main {
static int N = 51;

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
while (a-- > 0) {
int n = scanner.nextInt();
Node[] nodes = new Node[N];
for (int i = 1; i <= n; i++) {
int xx = scanner.nextInt();
int yy = scanner.nextInt();
nodes[i] = new Node(xx, yy);
}

boolean flag = true;
Arrays.sort(nodes, 1, n + 1, Comparator.comparingInt(o -> o.y));
nodes[0] = new Node(0,0);
for (int i = 1; i <= n; i++) {
int x = nodes[i].x;
int y = nodes[i].y;
int dx = Math.abs(x - nodes[i - 1].x);
int dy = Math.abs(y - nodes[i - 1].y);
if (dx > dy) {
flag = false;
break;
}
}
System.out.println(!flag? "Notabletocatch" : "Abletocatch");
}

}

static class Node {
int x = 0;
int y = 0;

public Node(int x, int y) {
this.x = x;
this.y = y;
}
}

}

``````
...全文
17 回复 打赏 收藏 转发到动态 举报

50,603

• 近7日
• 近30日
• 至今

刷题！