目录

  • 0. 前言
  • 1. 伪代码的基础语法
  • 2. 在word中插入伪代码
  • 2.1 Aurora和Miktex安装
  • 2.2 插入伪代码
  • 参考链接
  • 伪代码模板
  • 模板一
  • 模板二
  • 模板三
  • 模板四
  • 疑难杂症
  • 1. 显示中文?
  • 2. 特殊字符?
  • 3. 换行?
  • 0. 前言

    上一次接触伪代码可能还是在现代数字信号处理的课上,那时候只是学了个皮毛,照猫画虎瞎弄了一通,这次因为实际需要得好好学习一下,主要完成以下两个目标:

    1. 伪代码基础知识和语法;
    2. 在word中插入伪代码。

    1. 伪代码的基础语法

    教你写一手漂亮的伪代码(详细规则&简单实例)
    学会写伪代码

  • 每一条指令占一行,描述不出的指令可以用文字表示,语句后不接任何符号;
  • 分支、循环语句要有严格的缩进(与python一样),并有结束标记;
    for xxx do
    	if xxx then
    		...
    	else if xxx then
    		...
    	else
    		...
    	end if
    end for
    
  • 用“<-”来表示赋值
  • 2. 在word中插入伪代码

    流着泪终于把伪代码给加入到word里了。

    2.1 Aurora和Miktex安装

    Office -Word 公式插件Aurora的使用 ——在 Word 中插入 LaTex 公式 提供了安装包,文件解压后也会有安装步骤,在这里另外说明一下:
    (一)安装Micro-Miktex软件。其中“basic-miktex-2.9.7152.exe”文件是2.9版本的,在文件夹"aurora插件安装\Aurora2x\Micro-miktex"是2.5版本的,因此只要选一个下载即可,我选的是2.9版本的,并记一下自己安装的路径(在使用2.5的过程中出现了不能下载一些包的情况,2.9版本在安装过程中有个选项为自动下载必要的包)
    (二)安装Aurora。在提示需下载、安装Micro-Miktex时,跳过。
    (三)使用keygen进行破解Aurora。(上述安装包有提供keygen文件)

    2.2 插入伪代码

    1. 打开Aurora
      打开word(2019版本),点击“插入 – 对象”,出现以下界面,选择Aurora Equation点击确定,将出现以下窗口。

    2. 输入内容
      以下内容摘自:【Aurora】在word中插入算法伪代码、表格和公式
      开Aurora公式编辑框,在其中写入:

      \renewcommand{\thealgorithm}{1}
      \begin{algorithm}[H] 
      \caption{*******************************************} 
      \label{ABCLFRS}
      \begin{algorithmic}[1] 
      \Require{S,$\lambda$,T,k} 
      \Ensure{$\mathbf{w}_{222}$}\\ 
      \textbf{initialize}: Set $\mathbf{w}_1 = 0$ 
      \For{$t = 1,2,...,T$} 
      \State Choose $A_t \subset[m]$
      \EndFor
      \end{algorithmic} 
       
      \end{algorithm}
      

      并在编辑框中的Properties菜单中的Packages选项卡中填入所用到的包:

      \usepackage{amsmath}
      \usepackage{amssymb}
      % \usepackage{euler}
      \providecommand{\abs}[1]{\left\lvert#1\right\rvert}
      \providecommand{\norm}[1]{\left\lVert#1\right\rVert}
      \usepackage{bbm}
      \usepackage{CJK}
      \usepackage{listings}
      \usepackage{xcolor}
      \usepackage{listings}
      \usepackage{amsmath,bm,graphicx,multirow,bm,bbm,amssymb,psfrag,algorithm,subfigure,color,mdframed,wasysym,subeqnarray,multicol}
       
      \usepackage{algorithm}
      \usepackage{algpseudocode}
      \usepackage{amsmath}
      \renewcommand{\algorithmicrequire}{\textbf{Input:}}
      \renewcommand{\algorithmicensure}{\textbf{Output:}}
      

      最后Refresh一下,就可以得到最终的伪代码了,如下图所示:

    3. 解决Problems running LaTex问题
      一下内容参考:安装Aurora+miktex踩坑Problems running LaTex
      解决1:在Properties里的Rendering merhod选择vector或第三个vector(render all fonts)。

      解决2:Paths环境不对,应该是Miktex执行文件的位置

      解决3:添加环境变量

      win10系统环境变量怎么设置?

      解决4:将系统时间修改为2015年
      等成功后,再把日期改回来。
      Win10系统如何修改时间

    参考链接

    【Microsoft Word】Aurora插入公式点击Refresh,提示Problems running LaTex解决方法
    office中的Aurora公式插件,超好用(含下载安装包)
    Aurora problems running latex 的解决
    如何在Word中优雅地插入伪代码
    Latex中加入算法伪代码模板

    伪代码模板

    模板一

    \renewcommand{\thealgorithm}{1}
    \begin{algorithm}[H]
    \caption{algorithm caption} %算法的名字
    \hspace*{0.02in} {\bf Input:} %算法的输入, \hspace*{0.02in}用来控制位置,同时利用 \\ 进行换行
    input parameters A, B, C\\
    \hspace*{0.02in} {\bf Output:} %算法的结果输出
    output result
    \begin{algorithmic}[1]
    \State some description % \State 后写一般语句
    \For{condition} % For 语句,需要和EndFor对应
      \State ...
      \If{condition} % If 语句,需要和EndIf对应
        \State ...
      \Else
        \State ...
      \EndIf
    \EndFor
    \While{condition} % While语句,需要和EndWhile对应
      \State ...
    \EndWhile
    \State \Return result
    \end{algorithmic}
    \end{algorithm}
    

    模板二

    \begin{algorithm}[H]  
      \caption{Title}  
      \label{alg:Framwork}  
      \begin{algorithmic}  
        \Require  
        xxxxxxxx 
        \Ensure  
       xxxxxxxxx
          \For{xyz}
          \If {yyyyyyy}  
          \State asdfghjkl;
          \Else
          \State qwertyuiop;
           \If{zzzzzzz}
                 \State zxcvbnm;
           \EndIf
          \EndIf
       \EndFor  
        \For {abc }  
          \State qazwsxedc; 
        \EndFor
      \end{algorithmic}  
    \end{algorithm}
    

    模板三

    \begin{algorithm}[H] 
    	\caption{HHS}
    	\label{hhsa}
    	\begin{algorithmic}[1]  %1表示每隔一行编号	
    		\Require The original signal $x$.
    		\Ensure  The energy-time-frequency distribution of $x$. 
    		\Function{EMD}{$x, seg\_len$}
    		\State $ N \gets length(x) / seg\_len$;
    		\For {$i=1 \to i=N$}
    		\State $seg(i) \gets x(1+(i-1)*seg\_len : i*seg\_len)$;
    		\EndFor
    		\EndFunction
    	\end{algorithmic}
    \end{algorithm}
    

    模板四

    Latex写算法的伪代码排版

    疑难杂症

    1. 显示中文?

    2. 特殊字符?

    3. 换行?

    来源:橙橙小狸猫

    物联沃分享整理
    物联沃-IOTWORD物联网 » 伪代码学习与应用

    发表评论