202109-1(数组推导)
![](https://i-blog.csdnimg.cn/blog_migrate/641883e435d80d95b73c48c44580c9bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8fb394fea9dedbc24916c8d10b32d726.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b0d456f549bbc07ca5cc4a116919bc6d.png)
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] A = new int[n];
int[] B = new int[n];
for (int i = 0; i < n;i++){
B[i] = scanner.nextInt();
}
int sum_max=0, sum_min = 0, max = 0;
for (int i = 0; i < n; i++){
sum_max = sum_max + B[i];
}
System.out.println(sum_max);
for (int i = 0; i < n; i++){
if(max < B[i]){
max = B[i];
sum_min = sum_min + B[i];
}
}
System.out.println(sum_min);
}
}
202004-1(灰度图)
![](https://i-blog.csdnimg.cn/blog_migrate/9f39b86dad359439b6f89cee3991c27d.png)
![](https://i-blog.csdnimg.cn/blog_migrate/aba86e38558fd96d2c9254ff60283893.png)
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int k;
int m = scanner.nextInt();
int n = scanner.nextInt();
int L = scanner.nextInt();
int[] h = new int[256];
for(int i = 0; i < n ; i++){
for(int j = 0; j < m; j++){
k = scanner.nextInt();
h[k]++;
}
}
for(int i = 0; i < L ; i++){
System.out.print(h[i] + " ");
}
}
}
202012-1(期末预测之安全指数)
![](https://i-blog.csdnimg.cn/blog_migrate/d7c7a6d924d36e620ae990ce742f3853.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9276625aac385dd02bb70cd2cc39937c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4d09141077c69147c19bb9ad54080300.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int ReLU = 0;
int w, score;
for(int i = 0; i < n; i++){
w = scanner.nextInt();
score = scanner.nextInt();
ReLU = w * score + ReLU;
}
if(ReLU > 0){
System.out.println(ReLU);
}else{
System.out.println(0);
}
}
}
202009-1(称检测点查询)
![](https://i-blog.csdnimg.cn/blog_migrate/dca2f0f198223d03d36beafa162cc2dd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/55cb51f9cf13657b646e2114b4b4e897.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2947340d6b12148ea0c3cd100baad4a0.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int X = scanner.nextInt();
int Y = scanner.nextInt();
int D, min, k = 0;
int[] h = new int[n];
for(int i = 0; i < n; i++){
int x = scanner.nextInt();
int y = scanner.nextInt();
D = (X - x) * (X - x) + (Y - y) * (Y - y);
h[i]=D;
}
for(int i = 0; i < 3; i++){
k = 0;
min = h[0];
for(int j = 1; j < n; j++){
if(h[j] < min){
min = h[j];
k = j;
}
}
System.out.println(k + 1);
h[k] = 9999999;
}
}
}
201912-1(报数)
![](https://i-blog.csdnimg.cn/blog_migrate/3e53f4c9d136aeec68afcefe542fdfab.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d418b73421be4255d81ae01e25cd4899.png)
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int i = 1, a = 0, b = 0, c = 0, d = 0, p = 1;
while(p <= n){
if(i % 7 == 0 || i % 10 == 7 || i / 10 == 7 || i / 100 ==7 ||(i % 100) / 10 == 7){
if(i % 4 == 1){
a++;
}
else if(i % 4 == 2){
b++;
}
else if(i % 4 == 3){
c++;
}
else if(i % 4 == 0){
d++;
}
}
else{
p++;
}
i++;
}
// System.out.println(p+a+b+c+d);
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
}
201909-1(小明种苹果)
![](https://i-blog.csdnimg.cn/blog_migrate/c3ba8475e8d13dcf9c607feb74ffc7c8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/29d8df508232b0f95c74ed435560c42f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9098ce20390d03407c14297169f344fb.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int M = scanner.nextInt();
int T = 0, K = 0, k_i = 0, k_isum = 0, i_1 = 0;
int[][] A= new int[N][M+1];
for(int i = 0; i < N; i++){
for(int j = 0; j < M+1; j++){
A[i][j] = scanner.nextInt();
}
}
for(int i = 0; i < N; i++){
for(int j = 0; j < M+1; j++){
T += A[i][j];
}
}
System.out.print(T + " ");
for(int i = 0; i < N; i++){
k_isum = 0;
for(int j = 1; j < M+1; j++){
k_isum = A[i][j] + k_isum;
i_1 = i;
}
if(k_isum<0){
k_isum = -k_isum;
}
if(k_isum > K){
K = k_isum;
k_i = i_1;
}
}
System.out.print(k_i+1 + " " + K);
}
}
201903-1(小中大)
![](https://i-blog.csdnimg.cn/blog_migrate/7b7490b13d9b38c4ef0d9cacaf91ac46.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2ca998d7d83413ad759117d77f4ecc42.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
float[] A = new float[n];
for(int i = 0; i < n; i++){
A[i] = scanner.nextInt();
}
if(A[0] > A[n-1]){
int a = (int) A[0];
System.out.print(a + " ");
}
else{
int a = (int) A[n-1];
System.out.print(a + " ");
}
if(n % 2 == 1){
int a = (int) A[n / 2];
System.out.print(a + " ");
}
else{
float b = (A[n / 2 - 1] + A[n / 2]) / 2;
int c = (int) b;
if(b == c){
System.out.print(c + " ");
}
else{
System.out.printf("%.1f", b);
System.out.print(" ");
}
}
if(A[0] > A[n-1]){
int a = (int) A[n-1];
System.out.print(a);
}
else{
int a = (int) A[0];
System.out.print(a);
}
}
}
201812-1(小明上学)
![](https://i-blog.csdnimg.cn/blog_migrate/7e125994ec5c7ba84f0fdf4b724befc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/63ab362fc9739286a3f6e40e008f9a35.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
long r = scanner.nextLong();
long y = scanner.nextLong();
long g = scanner.nextLong();
int n = scanner.nextInt();
Long[][] A = new Long[n][2];
long s = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < 2; j++){
A[i][j] = scanner.nextLong();;
}
}
for(int i = 0; i < n; i++){
if(A[i][0] == 0){
s += A[i][1];
}
else if(A[i][0] == 1){
s += A[i][1];
}
else if(A[i][0] == 2){
s = s + A[i][1] + r;
}
else{
continue;
}
}
System.out.println(s);
}
}
201809-1(卖菜)
![](https://i-blog.csdnimg.cn/blog_migrate/ad60a84694ebd8e7003cc52f32b75a12.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] A = new int[n];
int[] B = new int[n];
for(int i = 0; i < n ; i++){
A[i] = scanner.nextInt();
}
for(int i = 0; i < n ; i++){
if(i == 0){
B[i] =(A[i] + A[i + 1]) / 2;
}
else if(i == n - 1){
B[i] =(A[i] + A[i - 1]) / 2;
}
else{
B[i] = (A[i + 1] + A[i] + A[i - 1]) / 3;
}
}
for(int i = 0; i < n ; i++){
System.out.print(B[i] + " ");
}
}
}
201803-1(跳一跳)
![](https://i-blog.csdnimg.cn/blog_migrate/a050dc4eca7781b5169d703b8413e140.png)
201712-1(最小差值)
![](https://i-blog.csdnimg.cn/blog_migrate/ba8058815080faa85d92937e27b9deca.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] A = new int[n];
int min = 999;
for(int i = 0; i < n; i++){
A[i] = scanner.nextInt();
}
for(int i = 0; i < n-1; ++i){
for(int j = i + 1; j < n; ++j){
if(A[j] > A[i]){
int t;
t = A[j];
A[j] = A[i];
A[i] = t;
}
}
}
for(int i = 0; i < n - 1; i++){
if(min > (A[i] - A[i+1])){
min = A[i] - A[i+1];
}
}
System.out.println(min);
}
}
201709-1(打酱油)
![](https://i-blog.csdnimg.cn/blog_migrate/ea0bc1400abbfd24f04b27d217034efd.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int i_5 = 0, i_3 = 0, i_1 = 0, free = 0, sum = 0;
if(N >= 50){
i_5 = N / 50;
free = i_5 * 2;
sum = sum + i_5 * 5 + free;
N = N - i_5 * 50;
}
if(N >= 30){
i_3 = N / 30;
free = i_3 * 1;
sum = sum + i_3 * 3 + free;
N = N - i_3 * 30;
}
if(N >= 10){
i_1 = N / 10;
sum = sum + i_1;
}
System.out.println(sum);
}
}
201703-1(分蛋糕)
![](https://i-blog.csdnimg.cn/blog_migrate/60c8409d914bffb706de2980190d6671.png)
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int[] A = new int[n];
int sum = 0, p = 0, j = 0, z = 0;
for(int i = 0; i < n; i++){
A[i] = scanner.nextInt();
}
for(int i = 0; i < n; i++){
sum = sum +A[i];
if(sum >= k){
p++;
sum = 0;
if(i == n -1){
z = 1;
}
}
if(i == n - 1 && z == 0){
p++;
}
}
System.out.println(p);
}
}