网易笔试 100 100 100 60
- 数字之和S(n)小于x
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int t = in.nextInt();
String res = "";
int l = t / 9;
if(t%9!=0)
res += t % 9;
for (int j = 0; j < l; j++) {
res+=9;
}
System.out.println(res);
}
}
}
- 翻倍
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
long a = in.nextInt();
long b = in.nextInt();
long p = in.nextInt();
long q = in.nextInt();
int res = 0;
while (a < b) {
if (a + p < b) {
p = p * q;
res++;
} else {
a += p;
res++;
}
}
System.out.println(res);
}
}
}
- 最大连续子序列个数
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int l = in.nextInt();
int[] arr = new int[l];
for (int j = 0; j < l; j++) {
arr[j] = in.nextInt();
}
int t = 0, res = 0, max = 0;
for (int j = 0; j < l; j++) {
if (arr[j] >= t) {
res++;
t += arr[j];
} else {
if (res > max) max = res;
res = 1;
t = arr[j];
}
}
System.out.println(max);
}
}
}
- 逆序列的距离和
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
long res = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] > arr[j]) {
res += j - i;
}
}
}
System.out.println(res);
}
}
#网易##笔试题目#