当前位置: 代码网 > it编程>编程语言>Java > SpringBoot中properties,yml,yaml的区别及使用说明

SpringBoot中properties,yml,yaml的区别及使用说明

2025年03月14日 Java 我要评论
springboot中的properties,yml,yaml的区别概述springboot中提供了两种配置文件properties和yml/yaml(yml和yaml是同一个意思)默认配置文件名称:

springboot中的properties,yml,yaml的区别

概述

  • springboot中提供了两种配置文件properties和yml/yaml(yml和yaml是同一个意思)
  • 默认配置文件名称:application
  • 在同一目录下的时候优先级为:properties>yml>yaml

书写格式

通过修改访问接口,来演示配置

properties:

server.port=8080
  • yml:
server:
	port: 8080

需要注意的是对于yml语法的:后面要加一个空格。

滑动窗口

  • 给定一个大小为 n≤106 的数组。
  • 有一个大小为 k 的滑动窗口,它从数组的最左边移动到最右边。
  • 你只能在窗口中看到 k 个数字。
  • 每次滑动窗口向右移动一个位置。

以下是一个例子:

该数组为 [1 3 -1 -3 5 3 6 7],k 为 3。

窗口位置 最小值 最大值
[1 3 -1] -3 5 3 6 7 -1 3
1 [3 -1 -3] 5 3 6 7 -3 3
1 3 [-1 -3 5] 3 6 7 -3 5
1 3 -1 [-3 5 3] 6 7 -3 5
1 3 -1 -3 [5 3 6] 7 3 6
1 3 -1 -3 5 [3 6 7] 3 7

你的任务是确定滑动窗口位于每个位置时,窗口中的最大值和最小值。

  • 输入格式
  • 输入包含两行。

第一行包含两个整数 n 和 k,分别代表数组长度和滑动窗口的长度。

第二行有 n 个整数,代表数组的具体数值。

同行数据之间用空格隔开。

  • 输出格式
  • 输出包含两个。

第一行输出,从左至右,每个位置滑动窗口中的最小值。

第二行输出,从左至右,每个位置滑动窗口中的最大值。

  • 输入样例:

8 3

1 3 -1 -3 5 3 6 7

  • 输出样例:

-1 -3 -3 -3 3 3
3 3 5 5 6 7

提交代码

c++

#include<iostream>
using namespace std;

const int n = 1000010;
int a[n], q[n], hh, tt = -1;

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++ i)    // 这个题要注意的是 q队列里面存放的是位置
    {
        scanf ("%d", &a[i]);        // 先求的是最小值
        if (i - k + 1 > q[hh]) ++hh;  // 如果最小值的位置已经滑出窗口了 然后就
                                    // ++ hh代表这个数已经没了
        while (hh <= tt && a[i] <= a[q[tt]]) -- tt; // 先确保队列里面有数字
                                    // 然后如果新来的数字要小于 队列里面的最小值
                                    // 那么--tt 就代表当前队列的最小值去掉
        q[++ tt] = i;  // 把新来的数字放到队列中
        if (i + 1 >= k) printf ("%d ", a[q[hh]]); // 当前队列的长度已经满足k了
                                    // 就可以把对首的元素输出出来
    }
    puts("");
    int hh = 0, tt = -1;
    for (int i = 0; i < n; ++ i)
    {
        if (i - k + 1 > q[hh]) ++ hh;
        while (hh <= tt && a[i] >= a[q[tt]]) -- tt;
        q[++ tt] = i;
        if (i + 1 >= k) printf("%d ", a[q[hh]]);
    }
    return 0;
}

java

import java.io.*;

public class main
{
    final static int n = 1000010;
    static int [] a = new int [n];
    static int [] q = new int [n];
    static int hh = 0, tt = -1;
    public static void main(string[] args) throws ioexception
    {
        int n, k;
        bufferedreader reader = new bufferedreader(new inputstreamreader(system.in));
        bufferedwriter out = new bufferedwriter(new outputstreamwriter(system.out));
        
        string [] str = reader.readline().split(" ");
        n = integer.parseint(str[0]);
        k = integer.parseint(str[1]);
        
        str = reader.readline().split(" ");
        for (int i = 0; i < n; ++ i) a[i] = integer.parseint(str[i]);
        
        // for (int i = 0; i < n; ++ i)
        // {
        //     if (hh <= tt && i - k + 1 > q[hh])  ++ hh;
        //     while (hh <= tt && a[i] <= a[q[hh]]) -- tt;
        //     q[++ tt] = i;
        //     if (i + 1 >= k) out.write(a[q[hh]]+" ");
        // }
        
        for(int i = 0; i < n; i ++)
        {
            if(hh <= tt && i - q[hh] + 1 > k) hh++;//判断队头是否已经滑出窗口
            while(hh <= tt && a[q[tt]] >= a[i]) tt--;//出队

            q[++tt] = i;//入队
            if(i >= k - 1) out.write(a[q[hh]]+" ");
        }
        
        out.write("\n");
        hh = 0;
        tt = -1;
        // for (int i  = 0; i < n; ++ i)
        // {
        //     if (hh <= tt && i - k + 1 > q[hh]) ++ hh;
        //     while (hh <= tt && a[i] >= a[q[hh]]) -- tt;
        //     q[++ tt] = i;
        //     if (i + 1 >= k) out.write(a[q[hh]]+" ");
        // }
        for(int i = 0; i < n; i ++)
        {
            if(hh <= tt && i - q[hh] + 1 > k) hh++;//判断队头是否已经滑出窗口
            while(hh <= tt && a[q[tt]] <= a[i]) tt--;//出队

            q[++tt] = i;//入队
            if(i >= k - 1) out.write(a[q[hh]]+" ");
        }
        out.flush();
        out.close();
    }
}

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com