1、导入宏包
\usepackage{algorithm}
\usepackage{algpseudocode}
下面这两行可以将 Require、Ensure 变成 Input、Output
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\begin{algorithm}
\caption{xxx} % 标题
\label{xx} % 用来引用
\begin{algorithmic}[1] % 加上 [1] 表示有序号
\Require xxxx % Requre 等同于 Input
\Ensure xxxx % Ensure 等同于 Output
\State xxxxx % 语句
\For {xxx}
\If {xxxx}
\State xxxx \Comment{This is a comment}
\EndIf
\EndFor
\Repeat
\State xxxx
\Until {xxx}
\State\Return xxx % Return 返回语句
\end{algorithmic}
\end{algorithm}
注意, 在这里,State,For , EndIf, EndFor ,要首字母大写,不同的宏包可能不同, \Comment 表示右侧的小三角形符号
而且Return 语句要另起一行,就必须加上 \State,即
\State\Return xxx % Return 返回语句
最终效果如下