Angwauh


私信TA

用户名:1710113018

访问量:32524

签 名:

你脚下曾踏过的泥沼,是你涤荡着强大的最好印证!

等  级
排  名 95
经  验 8428
参赛次数 6
文章发表 42
年  龄 19
在职情况 在职
学  校 河南农业大学
专  业 软件技术

  自我简介:

解题思路:
以第一项为基础,每读入一个数,就和第一项作比较,如果比第一项大,就直接保存在数组中,如果比第一项小就将数组中已有的数字向后移动一位,把当前读入的数放在第一位;
注意事项:

参考代码:

import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int a[] = new int[9];
			a[0] = sc.nextInt();
			int k = a[0];
			for (int j = 1; j < a.length; j++) {
				int b = sc.nextInt();
				if (b >= k) {
					a[j] = b;
				} else {
					for (int l = j; l >= 1; l--) {
						a[l] = a[l - 1];
					}
					a[0] = b;
				}
			}
			for (int j = 0; j < a.length; j++) {
				System.out.print(a[j] + " ");
			}
		}
	}
}


 

0.0分

3 人评分

  评论区