62,625
社区成员
发帖
与我相关
我的任务
分享import java.util.Scanner;
public class Test1092 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int b, i;
b = sc.nextInt();
int a[] = new int[b];
for (i = 0; i < b - 1; i++) {
a[i] = sc.nextInt();
}
for (i = 0; i < b - 1; i++) {
if (a[i] > a[i + 1] && a[i] > a[i - 1]) {
System.out.print(a[i] + " ");
}
}
}
}
public class Test13 {
//申明一个静态Integer数组
static Integer[] s;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int b, i;
b = sc.nextInt();
Integer a[] = new Integer[b];
for (i = 0; i < b; i++) {
a[i] = sc.nextInt();
}
SupportArray(a);
for (i = 0; i < s.length; i++) {
System.out.print(s[i] + ",");
}
}
static void SupportArray(Integer[] t) {
//申明一个list
List<Integer> list = new ArrayList<Integer>();
if (t.length >= 3) {
for (int i = 1; i < t.length - 1; i++) {
if (t[i] > t[i - 1] && t[i] > t[i + 1]) {
//把符合条件的数添加入list
list.add(t[i]);
}
}
//如果list不为空
if (list.size() > 0) {
//把list转为Integer数组存入静态数组中
s = list.toArray(new Integer[0]);
//再次递归
SupportArray(s);
}
}
}
}
import java.util.Scanner;
public class Test1092 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int b, i;
b = sc.nextInt();
int a[] = new int[b];
for (i = 0; i < b - 1; i++) {
a[i] = sc.nextInt();
}
int[] c = new int[b]; //用个临时数组保存支撑数查找结果
while (true) { //多套一层循环,直到找不到支撑数为止
int idx = 0; //c临时数组的下标
for (i = 1; i < b - 1; i++) { //这里要从1开始,否则会i-1会数组越姐
if (a[i] > a[i + 1] && a[i] > a[i - 1]) {
//System.out.print(a[i] + " ");
c[idx++] = a[I]; //把找到的支撑数保存到临时数组,c的下标跟着移动
}
}
if (idx == 0) break; //如果c的下标是0说明找不到支撑数,则推出while循环
b = idx; //获得保存支撑数的临时数组的长度
System.arraycopy(c, 0, a, 0, b); //把临时数组复制给a,重新查找
}
for (i=0; i<b; i++) { //打印最后结果
System.out.print(a[i] + " ");
}
}
}
public class Test {
public static void main(String[] args) {
int[] a = {1, 3, 2, 12, 1, 5, 3, 10, 7, 9, 8, 23, 85, 43};
int[] b = new int[a.length/2];
while (true) {
int index = 0;
for (int i = 1; i < a.length - 1; i++) {
if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
b[index++] = a[i];
}
}
if (index == 0) {
break;
} else {
a = arrSub(b,index);
}
}
System.out.println(Arrays.toString(a));
}
public static int[] arrSub(int[] arr, int len) {
int[] r = new int[len];
for (int i = 0; i < len; i++) {
r[i] = arr[i];
}
return r;
}
}