求矩阵的最大和最小值

时间限制: 1 Sec 内存限制: 128 MB

题目描述

定义一个函数用一级指针接收一个任意行任意列的矩阵并返回该矩阵元素的最大和最小值.

输入

矩阵的行数 矩阵的列数
矩阵各元素的值

输出

最大值
最小值

样例输入

3 3
1 2 3
4 5 6
7 8 9

样例输出

9
1

提示

解决方案

#include <iostream>

void findMinAndMaxValues(int *ptr, int row, int col);

int main() {
    int row, col;
    std::cin >> row >> col;
    int mat[row][col];
    for (int ir = 0; ir < row; ++ir) {
        for (int ic = 0; ic < col; ++ic) {
            std::cin >> mat[ir][ic];
        }
    }
    findMinAndMaxValues(&mat[0][0], row, col);

    return 0;
}

void findMinAndMaxValues(int *ptr, int row, int col) {
    int min = *ptr, max = *ptr;
    for (int ir = 0; ir < row; ++ir) {
        for (int ic = 0; ic < col; ++ic) {
            if (ptr[ir * col + ic] < min) {
                min = ptr[ir * col + ic];
            }
            if (ptr[ir * col + ic] > max) {
                max = ptr[ir * col + ic];
            }
        }
    }
    std::cout << max << std::endl << min << std::endl;
}

Node.js http-server

体验应该要好得多。如果你想把它当作一个简单的控制台上的 HTTP Server,可以先使用 npm 安装:

npm install --global http-server

然后就可以使用了:

http-server [path] [options]

使用 -p--port 来指定端口;使用 -a 来绑定地址;使用 -d 来指定目录。更多选项可以看文档。

你也可以直接:

npx http-server [path] [options]

引用:
http-server – npm
http-party/http-server: a simple zero-configuration command-line http server
The npm Blog — Introducing npx: an npm package runner

Python SimpleHTTPServer

这篇并不是在讨论 Python HTTP servers 的各种用法,而是记录给某些懒人们用的如何启动 SimpleHTTPServer。

正如其名,它只是个简单实现,因为安全等因素,你不应该把它用于生产环境。

如果你正在使用 Python2,那么你应该:

python -m SimpleHTTPServer 8000

如果你正在使用 Python3,那么:

python -m http.server 8000 --bind 127.0.0.1

从 3.4 开始,引入了参数 --bind;从 3.6 开始,参数 --bind 支持 IPv6。

从 3.7 开始,可以使用 --directory 来指定目录。

引用:
SimpleHTTPServer — Simple HTTP request handler
http.server — HTTP servers

CMake 指定源码目录和构建目录

在 CMake 3.13 或更新的版本中,可以使用:

cmake -S . -B build -G "Unix Makefiles"

来指定当前目录为源码目录,构建二进制文件到 build 文件夹中。

对于 CMake 3.13 之前的版本,需要给定没有写在文档中的参数:

cmake -H. -Bbuild -G "Unix Makefiles"

(参数和目录之间没有空格)

引用:
configuration – Getting CMake to build out of source without wrapping scripts – Stack Overflow