Skip to content

Commit 4534ed2

Browse files
committed
initial commit
0 parents  commit 4534ed2

12 files changed

+421
-0
lines changed

C++/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#C++版
2+
-----------------
3+
**下载**:<a href="https://github.com/soulmachine/acm-cheat-sheet/blob/master/C++/%E6%89%8B%E5%86%99%E4%BB%A3%E7%A0%81%E5%BF%85%E5%A4%87%E6%89%8B%E5%86%8C(C++%E7%89%88).pdf?raw=true">手写代码必备手册(C++版).pdf</a>
4+
5+
书的内容与Java版一摸一样,不过代码是用C++写的。本书的代码使用 C++ 11 标准。

C++/abstract.tex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
\subsubsection{内容简介}
2+
本书的目标读者是准备去北美找工作的码农,也适用于在国内找工作的码农,以及刚接触ACM算法竞赛的新手。
3+
4+
本书包含了 LeetCode Online Judge(\myurl{http://leetcode.com/onlinejudge})所有题目的答案,
5+
所有代码经过精心编写,编码规范良好,适合读者反复揣摩,模仿,甚至在纸上默写。
6+
7+
全书的代码,使用C++ 11的编写,并在 LeetCode Online Judge 上测试通过。本书中的代码规范,跟在公司中的工程规范略有不同,为了使代码短(方便迅速实现):
8+
9+
\begindot
10+
\item 所有代码都是单一文件。这是因为一般OJ网站,提交代码的时候只有一个文本框,如果还是
11+
按照标准做法,比如分为头文件.h和源代码.cpp,无法在网站上提交;
12+
13+
\item 大量使用 STL,让代码更短,shorter is better;
14+
15+
\item 不提倡防御式编程。不需要检查malloc()/new 返回的指针是否为NULL;不需要检查内部函数入口
16+
参数的有效性;使用纯C基于对象编程时,调用对象的成员方法,不需要检查对象自身是否为NULL。
17+
\myenddot
18+
19+
本手册假定读者已经学过《数据结构》\footnote{《数据结构》,严蔚敏等著,清华大学出版社,
20+
\myurl{http://book.douban.com/subject/2024655/}},
21+
《算法》\footnote{《Algorithms》,Robert Sedgewick, Addison-Wesley Professional, \myurl{http://book.douban.com/subject/4854123/}}
22+
这两门课,熟练掌握C++或Java。
23+
24+
\subsubsection{GitCafe地址}
25+
本书是开源的,项目地址:\myurl{https://gitcafe.com/soulmachine/LeetCode}

C++/chapProgrammingTrick.tex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
\chapter{编程技巧}
2+
把较大的数组放在main函数外,作为全局变量,这样可以防止栈溢出,因为栈的大小是有限制的。
3+
4+
如果能够预估栈,队列的上限,则不要用\fn{std::stack, std::queue},使用数组来模拟,这样速度最快。
5+
6+
输入数据一般放在全局变量,且在运行过程中不要修改这些变量。
7+
8+
在判断两个浮点数a和b是否相等时,不要用\fn{a==b},应该判断二者之差的绝对值\fn{fabs(a-b)}是否小于某个阀值,例如\fn{1e-9}。
9+

C++/format.cls

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
\usepackage[centering,paperwidth=180mm,paperheight=230mm,%
2+
body={390pt,530pt},marginparsep=10pt,marginpar=50pt]{geometry}
3+
\usepackage{color}
4+
\usepackage{enumitem}
5+
\usepackage{fancyvrb}
6+
\usepackage[bottom,perpage,symbol*]{footmisc}
7+
\usepackage{graphicx}
8+
\usepackage[hidelinks]{hyperref}
9+
\usepackage{makeidx}
10+
\usepackage[toc]{multitoc}
11+
\usepackage{pifont}
12+
\usepackage{underscore}
13+
\usepackage{amsmath}
14+
15+
\DefineFNsymbols*{chinese}{{\ding{172}}{\ding{173}}{\ding{174}}{\ding{175}}%
16+
{\ding{176}}{\ding{177}}{\ding{178}}{\ding{179}}{\ding{180}}{\ding{181}}}
17+
\setfnsymbol{chinese}
18+
19+
\hypersetup{bookmarksnumbered=true,bookmarksdepth=2}
20+
21+
\CTEXsetup[number={\thechapter}]{chapter}
22+
\CTEXsetup[format+={\raggedleft}]{chapter}
23+
\CTEXsetup[beforeskip={10pt}]{chapter}
24+
\CTEXsetup[afterskip={30pt}]{chapter}
25+
\def\CTEX@chapter@aftername{\par} % \CTEXsetup[aftername={\par}]{chapter}
26+
\CTEXsetup[format+={\raggedright}]{section}
27+
\CTEXsetup[beforeskip={-3.0ex plus -1ex minus -.2ex}]{section}
28+
\CTEXsetup[afterskip={2.3ex plus .2ex minus 0.2ex}]{section}
29+
30+
\renewcommand \thefigure{\thechapter-\arabic{figure}}
31+
\renewcommand \thetable{\thechapter-\arabic{table}}
32+
33+
\newcommand\figcaption[1]{\def\@captype{figure}\caption{#1}}
34+
\newcommand\tabcaption[1]{\def\@captype{table}\caption{#1}}
35+
36+
\long\def\@caption#1[#2]#3{%
37+
\addcontentsline{\csname ext@#1\endcsname}{#1}%
38+
{\protect\numberline{\csname fnum@#1\endcsname}{ \ignorespaces #2}}% change "the" to "fnum@"
39+
\normalsize
40+
\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}}
41+
42+
\long\def\@makecaption#1#2{%
43+
\vskip\abovecaptionskip
44+
\sbox\@tempboxa{#1\quad#2}%
45+
\ifdim \wd\@tempboxa >\hsize
46+
#1\quad#2\par
47+
\else
48+
\global \@minipagefalse
49+
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
50+
\fi
51+
\vskip\belowcaptionskip}
52+
53+
\setlength\abovecaptionskip{0pt}
54+
55+
%\setmainfont{Times New Roman}
56+
\setmainfont{Linux Libertine O}
57+
%\setmainfont{TeX Gyre Pagella}
58+
\newfontfamily\urlfont{PT Sans Narrow}
59+
%\setmonofont[AutoFakeBold=1.6,AutoFakeSlant=0.17,Mapping=tex-text-tt]{Inconsolata}
60+
\setCJKfamilyfont{zhyou}{YouYuan}
61+
62+
\newcommand{\fn}[1]{\texttt{#1}}
63+
\newcommand{\sfn}[1]{\texttt{\small #1}}
64+
\newcommand{\kw}[1]{\textsf{#1}}
65+
\newcommand{\myurl}[1]{{\urlfont #1}}
66+
\newcommand{\mpar}[1]{\marginpar[\hfill\kaishu #1]{\kaishu #1}}
67+
\newcommand{\mn}[1]{\texttt{\bs #1}}
68+
\renewcommand{\today}{\the\year-\the\month-\the\day}
69+
\newcommand\bs{\textbackslash}
70+
71+
\newcommand\begindot{\begin{itemize}
72+
[itemsep=2pt plus 2pt minus 2pt,%
73+
topsep=3pt plus 2pt minus 2pt,%
74+
parsep=0pt plus 2pt minus 2pt]}
75+
\newcommand\myenddot{\end{itemize}}
76+
77+
\newcommand\beginnum{\begin{enumerate}
78+
[itemsep=2pt plus 2pt minus 2pt,%
79+
topsep=3pt plus 2pt minus 2pt,%
80+
parsep=0pt plus 2pt minus 2pt]}
81+
\newcommand\myendnum{\end{enumerate}}
82+
83+
\DefineVerbatimEnvironment%
84+
{Code}{Verbatim}
85+
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm}
86+
87+
\raggedbottom
88+
%\setlength{\parskip}{1ex plus .5ex minus .5ex}
89+
90+
\input{verbatim.cls}
91+
\DefineVerbatimEnvironment%
92+
{Codex}{Verbatim}
93+
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm,%
94+
frame=lines,labelposition=all,framesep=5pt}
95+
96+
\DefineVerbatimEnvironment%
97+
{Code}{Verbatim}
98+
{fontsize=\small,baselinestretch=0.9,xleftmargin=3mm}
99+
100+
\makeindex

C++/leetcode-cpp.tex

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
\documentclass[10pt,adobefonts,fancyhdr,hyperref,UTF8]{ctexbook}
2+
3+
\usepackage{multirow}
4+
% for \soul 删除线
5+
\usepackage{ulem}
6+
% 表头斜线
7+
\usepackage{diagbox}
8+
9+
\makeatletter
10+
\input{format.cls}
11+
\makeatother
12+
13+
\begin{document}
14+
\sloppy
15+
\newcommand\BookTitle{LeetCode题解}
16+
\pagestyle{fancy}
17+
\fancyhf{}
18+
\fancyhead[RE]{\normalfont\small\rmfamily\nouppercase{\leftmark}}
19+
\fancyhead[LO]{\normalfont\small\rmfamily\nouppercase{\rightmark}}
20+
\fancyhead[LE,RO]{\thepage}
21+
%\fancyfoot[LE,LO]{\small\normalfont\youyuan\BookTitle}
22+
%\fancyfoot[RE,RO]{\textsf{\small \color{blue} https://gitcafe.com/soulmachine/LeetCode}}
23+
24+
\makeatletter
25+
\@openrightfalse
26+
\makeatother
27+
28+
\frontmatter % 开始前言目录,页码用罗马数字
29+
30+
\include{title}
31+
32+
\tableofcontents
33+
34+
\mainmatter % 开始正文,页码用阿拉伯数字
35+
36+
\graphicspath{{diagrams/}}
37+
38+
\include{chapProgrammingTrick}
39+
40+
\appendix % 开始附录,章用字母编号
41+
\printindex
42+
43+
\end{document}

C++/tex-text-tt.map

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; TECkit mapping for TeX input conventions <-> Unicode characters
2+
3+
LHSName "TeX-text"
4+
RHSName "UNICODE"
5+
6+
pass(Unicode)
7+
8+
; ligatures from Knuth's original CMR fonts
9+
;U+002D U+002D <> U+2013 ; -- -> en dash
10+
;U+002D U+002D U+002D <> U+2014 ; --- -> em dash
11+
12+
;U+0027 <> U+2019 ; ' -> right single quote
13+
;U+0027 U+0027 <> U+201D ; '' -> right double quote
14+
;U+0022 > U+201D ; " -> right double quote
15+
16+
;U+0060 <> U+2018 ; ` -> left single quote
17+
;U+0060 U+0060 <> U+201C ; `` -> left double quote
18+
19+
;U+0021 U+0060 <> U+00A1 ; !` -> inverted exclam
20+
;U+003F U+0060 <> U+00BF ; ?` -> inverted question
21+
22+
; additions supported in T1 encoding
23+
;U+002C U+002C <> U+201E ; ,, -> DOUBLE LOW-9 QUOTATION MARK
24+
;U+003C U+003C <> U+00AB ; << -> LEFT POINTING GUILLEMET
25+
;U+003E U+003E <> U+00BB ; >> -> RIGHT POINTING GUILLEMET
26+
27+
;U+0027 <> U+2019 ; ' -> right single quote
28+
;U+0022 > U+201D ; " -> right double quote

C++/tex-text-tt.tec

92 Bytes
Binary file not shown.

C++/title.aux

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
\relax
2+
\providecommand\hyper@newdestlabel[2]{}
3+
\@writefile{toc}{\contentsline {subsubsection}{内容简介}{i}{section*.1}}
4+
\FN@pp@footnote@aux{1}{i}
5+
\FN@pp@footnote@aux{2}{i}
6+
\@writefile{toc}{\contentsline {subsubsection}{GitCafe地址}{i}{section*.2}}
7+
\FN@pp@footnotehinttrue
8+
\@setckpt{title}{
9+
\setcounter{page}{2}
10+
\setcounter{equation}{0}
11+
\setcounter{enumi}{0}
12+
\setcounter{enumii}{0}
13+
\setcounter{enumiii}{0}
14+
\setcounter{enumiv}{0}
15+
\setcounter{footnote}{0}
16+
\setcounter{mpfootnote}{0}
17+
\setcounter{CTEX@sectiondepth}{2}
18+
\setcounter{part}{0}
19+
\setcounter{chapter}{0}
20+
\setcounter{section}{0}
21+
\setcounter{subsection}{0}
22+
\setcounter{subsubsection}{0}
23+
\setcounter{paragraph}{0}
24+
\setcounter{subparagraph}{0}
25+
\setcounter{figure}{0}
26+
\setcounter{table}{0}
27+
\setcounter{FancyVerbLine}{0}
28+
\setcounter{pp@next@reset}{3}
29+
\setcounter{@fnserial}{2}
30+
\setcounter{Item}{0}
31+
\setcounter{Hfootnote}{2}
32+
\setcounter{Hy@AnnotLevel}{0}
33+
\setcounter{bookmark@seq@number}{0}
34+
\setcounter{parentequation}{0}
35+
\setcounter{section@level}{3}
36+
}

C++/title.tex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
\thispagestyle{plain}
2+
\begin{center}
3+
{\LARGE\textbf{\BookTitle}}
4+
5+
\vspace{1em}
6+
{\large 戴方勤 ([email protected])}
7+
8+
\vspace{1ex}
9+
\myurl{https://gitcafe.com/soulmachine/LeetCode}
10+
11+
\vspace{1ex}
12+
最后更新 \today
13+
14+
\vspace{1em}
15+
\textbf{\large 版权声明}
16+
\end{center}
17+
\noindent 本作品采用“Creative Commons 署名-非商业性使用-相同方式共享 3.0 Unported许可协议
18+
(cc by-nc-sa)”进行许可。
19+
\texttt{\small http://creativecommons.org/licenses/by-nc-sa/3.0/}
20+
21+
\vspace{1em}
22+
\input{abstract}

C++/verbatim.cls

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
\def\FV@SetLineWidth{%
2+
\if@FV@ResetMargins\else
3+
\advance\leftmargin\@totalleftmargin
4+
\fi
5+
\advance\leftmargin\FV@XLeftMargin\relax
6+
\advance\rightmargin\FV@XRightMargin\relax
7+
\linewidth\hsize
8+
%\advance\linewidth-\leftmargin
9+
%\advance\linewidth-\rightmargin
10+
\hfuzz\FancyVerbHFuzz\relax}
11+
12+
13+
\def\FV@SingleFrameLine#1{%
14+
%% DG/SR modification end
15+
\hbox to\z@{%
16+
%\kern\leftmargin
17+
%% DG/SR modification begin - Jun. 22, 1998
18+
\ifnum#1=\z@
19+
\let\FV@Label\FV@LabelBegin
20+
\else
21+
\let\FV@Label\FV@LabelEnd
22+
\fi
23+
\ifx\FV@Label\relax
24+
%% DG/SR modification end
25+
\FancyVerbRuleColor{\vrule \@width\linewidth \@height\FV@FrameRule}%
26+
%% DG/SR modification begin - Jun. 22, 1998
27+
\else
28+
\ifnum#1=\z@
29+
\setbox\z@\hbox{\strut\enspace\urlfont\FV@LabelBegin\strut}%
30+
\else
31+
\setbox\z@\hbox{\strut\enspace\urlfont\FV@LabelEnd\strut}%
32+
\fi
33+
\@tempdimb=\dp\z@
34+
\advance\@tempdimb -.5\ht\z@
35+
\@tempdimc=\linewidth
36+
\advance\@tempdimc -\wd\z@
37+
%\divide\@tempdimc\tw@
38+
\ifnum#1=\z@ % Top line
39+
\ifx\FV@LabelPositionTopLine\relax
40+
\FancyVerbRuleColor{\vrule \@width\linewidth \@height\FV@FrameRule}%
41+
\else
42+
\FV@FrameLineWithLabel
43+
\fi
44+
\else % Bottom line
45+
\ifx\FV@LabelPositionBottomLine\relax
46+
\FancyVerbRuleColor{\vrule \@width\linewidth \@height\FV@FrameRule}%
47+
\else
48+
\FV@FrameLineWithLabel
49+
\fi
50+
\fi
51+
\fi
52+
%% DG/SR modification end
53+
\hss}}
54+
55+
56+
%% DG/SR modification begin - May. 19, 1998
57+
\def\FV@FrameLineWithLabel{%
58+
\ht\z@\@tempdimb\dp\z@\@tempdimb%
59+
\FancyVerbRuleColor{%
60+
\raise 0.5ex\hbox{\vrule \@width\@tempdimc \@height\FV@FrameRule}%
61+
\raise\@tempdimb\box\z@}}
62+
%% DG/SR modification end
63+
64+
65+
\def\FV@EndListFrame@Lines{%
66+
\begingroup
67+
%\vskip 0.5ex
68+
\baselineskip\z@skip
69+
\kern\FV@FrameSep\relax
70+
%% DG/SR modification begin - May. 19, 1998
71+
%% \FV@SingleFrameLine
72+
\FV@SingleFrameLine{\@ne}%
73+
%% DG/SR modification end
74+
\endgroup}
75+
76+
\newskip\mytopsep
77+
\setlength{\mytopsep}{4pt plus 2pt minus 3pt}
78+
79+
\def\FV@ListVSpace{%
80+
\@topsepadd\mytopsep
81+
\if@noparlist\advance\@topsepadd\partopsep\fi
82+
\if@inlabel
83+
\vskip\parskip
84+
\else
85+
\if@nobreak
86+
\vskip\parskip
87+
\clubpenalty\@M
88+
\else
89+
\addpenalty\@beginparpenalty
90+
\@topsep\@topsepadd
91+
\advance\@topsep\parskip
92+
\addvspace\@topsep
93+
\fi
94+
\fi
95+
%\showthe \@topsepadd
96+
%\showthe \topsep
97+
%\showthe \partopsep
98+
%\showthe \parskip
99+
\global\@nobreakfalse
100+
\global\@inlabelfalse
101+
\global\@minipagefalse
102+
\global\@newlistfalse}
103+
104+
\def\FV@EndList{%
105+
\FV@ListProcessLastLine
106+
\FV@EndListFrame
107+
%\showthe \@topsepadd
108+
\@endparenv
109+
\endgroup
110+
\@endpetrue}
111+
112+
\def\theFancyVerbLine{\sffamily\scriptsize\arabic{FancyVerbLine}}

0 commit comments

Comments
 (0)