我有以下用于打印算法的代码
但是,我希望在 For 循环之前有输入和输出。
例如输入:配料 I = (1, \ldots, N),输出:披萨
对此有一个很好的解决方案吗?
\documentclass[12pt]{beamer}
\usepackage{algorithm,algorithmic}
\begin{document}
\begin{frame}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\FOR{$j=1$ to $N$}
\STATE Add Pineapple on Pizza
\ENDFOR
\end{algorithmic}
\caption{pseudocode for making a pizza}
\label{alg:seq}
\end{algorithm}
\end{frame}
\end{document}
答案1
像这样吗?
\documentclass[12pt]{beamer}
\usepackage{algorithm,algorithmic}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\begin{document}
\begin{frame}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\REQUIRE ingredients I = (1, \ldots, N)
\ENSURE not Pizza
\FOR{$j=1$ to $N$}
\STATE Add Pineapple on Pizza
\ENDFOR
\end{algorithmic}
\caption{pseudocode for not making a pizza}
\label{alg:seq}
\end{algorithm}
\end{frame}
\end{document}