求一个用algorithmic包写伪代码的示例,包括input、for、if,不能使用algorithm,algorithm2e?

发布于 2022-04-09 17:23:48

求一个用algorithmic包写伪代码的示例,包括input、for、if,不能使用algorithm,algorithm2e

查看更多

关注者
0
被浏览
1.2k
2 个回答
Bolshevik
Bolshevik 2022-04-09
这家伙很懒,什么也没写!
\documentclass{IEEEtran}
\usepackage[commentColor=black]{algpseudocodex}
\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}


\usepackage[most]{tcolorbox}
\tcbset{
  standard jigsaw,
  sharp corners=all,
  colframe=black,
  opacityback=0,
  boxsep=0pt,
  boxrule=0.5pt,
  top=5pt,
  bottom=5pt,
  left=5pt,
  right=5pt,
  beforeafter skip=10pt
}


\begin{document}

\begin{figure}
\rule{\linewidth}{1pt}
\begin{algorithmic}[1]
\Require something
\Ensure something
\State $sum\gets 0$
\LComment{The next two lines increment both $x$ and $y$.}
\For{$i\gets 1, n$}
\State $sum\gets sum+i$ \Comment{Increment $x$.}
\EndFor
\While{$i\gets 1, n$}
\State $sum\gets sum+i$
\EndWhile
\If{$quality\ge 9$}
\State $a\gets perfect$
\ElsIf{$quality\ge 7$}
\State $a\gets good$
\ElsIf{$quality\ge 5$}
\State $a\gets medium$
\ElsIf{$quality\ge 3$}
\State $a\gets bad$
\Else
\State $a\gets unusable$
\EndIf
\end{algorithmic}
\rule[.8em]{\linewidth}{1pt}
\caption{XXX}
\label{XXX}
\end{figure}

\begin{figure}
\begin{tcolorbox}

\begin{algorithmic}[1]
\Require something
\Ensure something
\State $sum\gets 0$
\LComment{The next two lines increment both $x$ and $y$.}
\For{$i\gets 1, n$}
\State $sum\gets sum+i$ \Comment{Increment $x$.}
\EndFor
\While{$i\gets 1, n$}
\State $sum\gets sum+i$
\EndWhile
\If{$quality\ge 9$}
\State $a\gets perfect$
\ElsIf{$quality\ge 7$}
\State $a\gets good$
\ElsIf{$quality\ge 5$}
\State $a\gets medium$
\ElsIf{$quality\ge 3$}
\State $a\gets bad$
\Else
\State $a\gets unusable$
\EndIf
\end{algorithmic}
\end{tcolorbox}
\caption{XXX}
\label{XXX1}
\end{figure}


\end{document}
LaTeXStudio
LaTeXStudio 2022-04-09
这家伙很懒,什么也没写!

没看懂问题是什么,看看这个代码:

 \documentclass{IEEEtran}

\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}

 \begin{algorithm}[H]
 \caption{Algorithm for ...}
 \begin{algorithmic}[1]
 \renewcommand{\algorithmicrequire}{\textbf{Input:}}
 \renewcommand{\algorithmicensure}{\textbf{Output:}}
 \REQUIRE in
 \ENSURE  out
 \\ \textit{Initialisation} :
  \STATE first statement
 \\ \textit{LOOP Process}
  \FOR {$i = l-2$ to $0$}
  \STATE statements..
  \IF {($i \ne 0$)}
  \STATE statement..
  \ENDIF
  \ENDFOR
 \RETURN $P$
 \end{algorithmic}
 \end{algorithm}

\end{document} 

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览