P1046题目要求
P1046题解
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int counter = 0;
int[] array = new int[10];
for (int i = 0; i < 10; i++) {
array[i] = scanner.nextInt();
}
int height = scanner.nextInt() + 30;
for (int i = 0; i < 10; i++) {
if (array[i] <= height) {
counter++;
}
}
System.out.println(counter);
scanner.close();
}
}
P1047题目要求
P1047题解
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt();
int lineNum = scanner.nextInt();
int counter = 0;
//注意树维L+1棵
int[] array = new int[length+1];
for (int i = 0; i < lineNum; i++) {
int from = scanner.nextInt(), to = scanner.nextInt();
for (int j = from; j <= to; j++) {
array[j] = 1;
}
}
for (int i = 0; i <= length; i++) {
if (array[i] == 0) {
counter++;
}
}
System.out.println(counter);
scanner.close();
}
}
P1427题目要求
P1427题解
以前写的,竟然还用了ArrayList……
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> array = new ArrayList<>();
Scanner scan = new Scanner(System.in);
while(scan.hasNext()) {
int x = scan.nextInt();
if (x != 0) {
array.add(x);
} else {
break;
}
}
int length = array.size();
for (int i = length-1; i >= 0; i--) {
System.out.print(array.get(i) + " ");
}
scan.close();
}
}
P1428题目要求
P1428题解
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] array = new int[n];
int[] result = new int[n];
int m;
int count;
for (int i = 0; i < n; i++) {
m = scan.nextInt();
array [i] = m;
count = 0;
for (int j = i; j>=0; j--) {
if (array [i] > array [j]) {
count++;
}
}
result[i] = count;
}
for (int i : result) {
System.out.print(i + " ");
}
scan.close();
}
}
P2141题目要求
P2141题解
这题小麻烦一些,解题历程
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
int[] array = new int[num];
for (int i = 0; i < num; i++) {
array[i] = scanner.nextInt();
}
int[] counterArr = new int[num];
for (int i = 0; i < num; i++) {
int now = array[i];
for (int j = 0; j < num; j++) {
if (j == i) {
continue;
}
int num1 = array[j];
for (int k = 0; k < num; k++) {
if (k == i || k == j) {
continue;
}
int num2 = array[k];
if (num1 + num2 == now) {
counterArr[i] = 1;
break;
}
}
}
}
int counter = 0;
for (int i = 0; i < num; i++) {
if (counterArr[i] == 1) {
counter++;
}
}
System.out.println(counter);
scanner.close();
}
}
P1567题目要求
P1567题解
这个题太难了,性能卡的太死了,1s+125MB的双限制在本题中,对Java用户来说太难了!!!!!!强烈谴责!!!
辛酸的解题历程
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int num = reader.read();
reader.readLine();
String[] arr = reader.readLine().split(" ");
int counter = 0;
int max = 0;
for (int i = 1; i < arr.length; i++) {
int tem1 = Integer.parseInt(arr[i]);
int tem2 = Integer.parseInt(arr[i-1]);
if((tem1 - tem2) > 0) {
counter++;
} else {
max=Math.max(max, counter);
counter = 0;
}
}
System.out.println(max+1);
}
}