\documentclass[12pt,a4paper]{article}
\usepackage{ctex}
\usepackage{amsmath,amscd,amsbsy,amssymb,latexsym,url,bm,amsthm}
%%\usepackage[boxed,commentsnumbered,ruled]{algorithm2e}
\usepackage[lined,boxed,commentsnumbered,linesnumbered,ruled]{algorithm2e} %%����end
\usepackage{epsfig,graphicx,subfigure}
\usepackage{enumitem,balance,mathtools}
\usepackage{wrapfig}
\usepackage{mathrsfs, euscript}
\usepackage[usenames]{xcolor}
\usepackage{hyperref}
\usepackage{caption}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}
\newtheorem{corollary}{Corollary}
\newtheorem{exercise}{Exercise}
\newtheorem*{solution}{Solution}

\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\newcommand{\postscript}[2]
 {\setlength{\epsfxsize}{#2\hsize}
  \centerline{\epsfbox{#1}}}

\renewcommand{\baselinestretch}{1.0}

\setlength{\oddsidemargin}{-0.365in}
\setlength{\evensidemargin}{-0.365in}
\setlength{\topmargin}{-0.3in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textheight}{10.1in}
\setlength{\textwidth}{7in}
\makeatletter \renewenvironment{proof}[1][Proof] {\par\pushQED{\qed}\normalfont\topsep6\p@\@plus6\p@\relax\trivlist\item[\hskip\labelsep\bfseries#1\@addpunct{.}]\ignorespaces}{\popQED\endtrivlist\@endpefalse} \makeatother
\makeatletter
\renewenvironment{solution}[1][Solution] {\par\pushQED{\qed}\normalfont\topsep6\p@\@plus6\p@\relax\trivlist\item[\hskip\labelsep\bfseries#1\@addpunct{.}]\ignorespaces}{\popQED\endtrivlist\@endpefalse} \makeatother
\begin{document}
\noindent

%========================================================================
\noindent\framebox[\linewidth]{\shortstack[c]{
\Large{\textbf{Algorithm2e�����ʾ}}\vspace{1mm}\\
Help Document for CS101-Introduction to Computer Science, Xiaofeng Gao@SJTU}}


\begin{enumerate}

\item {\color{blue}\textbf{If��估�㷨ģ�����������Դ���룬�Ҳ���������}}

\begin{minipage}[t]{0.5\textwidth}

\begin{verbatim}
\begin{algorithm}[H]
\KwIn{$x$, $y$}
\KwOut{$sign$}
\BlankLine
\caption{$div(x,y)$} \label{Alg-div}
\If{$rm(x,y)=0$}{
    $sign=1$\;
}
\Else{
    $sign=0$\;
}
\Return{$sign$}\;
\end{algorithm}
\end{verbatim}
\end{minipage}
\hspace{2mm}
\begin{minipage}[t]{0.4\textwidth}
\begin{algorithm}[H]
%\LinesNumbered
\KwIn{$x$, $y$}
\KwOut{$sign$}
\BlankLine
\caption{$div(x,y)$} \label{Alg-div}
\eIf{$rm(x,y)=0$}{
    $sign \leftarrow 1$\;
}{
    $sign \leftarrow 0$\;
}
\Return{$sign$}\;
\end{algorithm}
\end{minipage}


\item {\color{blue}\textbf{If-ElseIf-Else���������}}

\begin{minipage}[t]{0.5\textwidth}
\begin{verbatim}
\begin{algorithm}[H]
\KwIn{$score$}
\KwOut{Letter Grade}
\BlankLine
\caption{LetterGrade($score$)}
\label{Alg-Score}
\uIf{$score \ge 90$}{
    \textbf{output} $A$\;
}
\uElseIf{$80 \le score < 90$}{
    \textbf{output} $B$\;
}
\Else{
    \textbf{output} $P$\;
}
\end{algorithm}
\end{verbatim}
\end{minipage}
\hspace{2mm}
\begin{minipage}[t]{0.4\textwidth}
\begin{algorithm}[H]
\KwIn{$score$}
\KwOut{Letter Grade}
\BlankLine
\caption{LetterGrade($score$)} \label{Alg-Score}

\uIf{$score \ge 90$}{
    \textbf{output} $A$\;
}
\uElseIf{$80 \le score < 90$}{
    \textbf{output} $B$\;
}
\Else{
    \textbf{output} $P$\;
}
\end{algorithm}
\end{minipage}

\item {\color{blue}\textbf{While���������}}

\begin{minipage}[t]{0.5\textwidth}
\begin{verbatim}
\begin{algorithm}[H]
\KwIn{$x$, $y$}
\KwOut{$x$}
\BlankLine
\While{$x \ge y$}{
$x-=y$\;
}
\textbf{output} $x$\;
\end{algorithm}
\end{verbatim}
\end{minipage}
\hspace{2mm}
\begin{minipage}[t]{0.4\textwidth}
\begin{algorithm}[H]
\KwIn{$x$, $y$}
\KwOut{$x$}
\BlankLine
\caption{$rm(x,y)$} \label{Alg-rm}
\While{$x \ge y$}{
$x-=y$\;
}
\textbf{output} $x$\;
\end{algorithm}
\end{minipage}

\newpage
\item {\color{blue}\textbf{For���������}}

\begin{minipage}[t]{0.5\textwidth}
\begin{verbatim}
\begin{algorithm}[H]
\KwIn{$n \in \mathbb{N}$}
\KwOut{The sum from 1 to $n$}
\BlankLine
\caption{Sum($n$)} \label{Alg-Sum}
$sum=0$\;
\For{$temp=0$ to $n$}{
    $sum=sum+temp$\;
}
\textbf{output} $sum$\;
\end{algorithm}
\end{verbatim}
\end{minipage}
\hspace{2mm}
\begin{minipage}[t]{0.4\textwidth}
\begin{algorithm}[H]
\KwIn{$n \in \mathbb{N}$}
\KwOut{The sum from 1 to $n$}
\BlankLine
\caption{Sum($n$)} \label{Alg-Sum}
$sum \leftarrow 0$\;
\For{$temp=0$ to $n$}{
    $sum \leftarrow sum+temp$\;
}
\textbf{output} $sum$\;
\end{algorithm}
\end{minipage}

\item {\color{blue}\textbf{Repeat-Until���������}}

\begin{minipage}[t]{0.5\textwidth}
\begin{verbatim}
\begin{algorithm}[H]
\KwIn{$a, b \in \mathbb{N}$}
\KwOut{Greatest common divide of $a$, $b$}
\BlankLine
\caption{GCD($a$, $b$)} \label{Alg-GCD}

\Repeat{$gcd=0$}{
    $gcd = a \mod b$\;
    $a=b$\;
    $b=gcd$\;
}
\textbf{output} $gcd$\;
\end{algorithm}
\end{verbatim}
\end{minipage}
\hspace{2mm}
\begin{minipage}[t]{0.4\textwidth}
\begin{algorithm}[H]
\KwIn{$a, b \in \mathbb{N}$}
\KwOut{Greatest common divisor of $a$, $b$}
\BlankLine
\caption{GCD($a$, $b$)} \label{Alg-GCD}

\Repeat{$gcd=0$}{
    $gcd \leftarrow a \mod b$\;
    $a \leftarrow b$\;
    $b \leftarrow gcd$\;
}
\textbf{output} $gcd$\;
\end{algorithm}
\end{minipage}

\item {\color{blue}\textbf{Case���������}}

\begin{minipage}[t]{0.5\textwidth}
\begin{verbatim}
\begin{algorithm}[H]
\KwIn{$person$}
\KwOut{$person$'s gender}
\BlankLine
\caption{Gender} \label{Alg-Gender}
\Switch{$person$}{
\uCase{$person.gender=male$}{
	\textbf{output} Male\;
}
\uCase{$person.gender=female$}{
	\textbf{output} Female\;
}
\Other{
	\textbf{output} Unknown\;
}
}
\end{algorithm}
\end{verbatim}
\end{minipage}
\hspace{2mm}
\begin{minipage}[t]{0.4\textwidth}
\begin{algorithm}[H]
\KwIn{$person$}
\KwOut{$person$'s gender}
\BlankLine
\caption{Gender} \label{Alg-Gender}
\Switch{$person$}{
\uCase{$person.gender=male$}{
	\textbf{output} Male\;
}
\uCase{$person.gender=female$}{
	\textbf{output} Female\;
}
\Other{
	\textbf{output} Unknown\;
}
}
\end{algorithm}
\end{minipage}
\end{enumerate}

{\color{blue}���������ͽ�����ο�AlgorithmPackage.pdf�����ĵ���}

%========================================================================
\end{document}
