forked from julycoding/The-Art-Of-Programming-By-July-2nd
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request julycoding#1 from julycoding/master
2014-01-14
- Loading branch information
Showing
53 changed files
with
1,539 additions
and
2,995 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#Build epub Books | ||
|
||
##Requirement | ||
* pandoc | ||
|
||
##Usage | ||
* chmod +x generate.sh | ||
|
||
This will generate TAOP_July.epub for you. | ||
|
||
##Notice | ||
|
||
The script will **reset** your repo's status. Please **commit** before start generating. | ||
|
||
注意: 这个脚本由于使用了`git reset`, 会重置你的库的状态.如果在生成前对库里的文件有任何的修改,请先`commit`提交后再调用生成脚本. | ||
|
||
Reason for that: | ||
|
||
* some **image link** in .md file ended with **?raw=true** | ||
* while `pandoc` processing convert, it will **failed** to read such file | ||
* So, this script do some preprocess, remove all that tail of image link | ||
* After generation, `git reset` is performed to reset those files | ||
|
||
原因: | ||
|
||
* 有些图片在引用时的路径添加上了?raw=true | ||
* 当pandoc处理时,其读取不到相应的文件,导致无法继承图片到图书中 | ||
* 为了解决这个问题,生成脚本做了一些预处理,删除掉了图片链接中的?raw=true | ||
* 在生成后,脚本调用了`git reset`,来重置这些预处理 | ||
|
||
|
||
##Bugs | ||
* 03.04.md | ||
* image lost in 03.04.md(because of img wrapped in \<img\>) | ||
* when reading in ibooks, error reported in several chapter(Maybe due to informal format) | ||
* 第三章再续:快速选择SELECT算法的深入分析与实现 | ||
* 第三章:寻找最小的 k 个数 | ||
* 第三章:寻找最小的 k 个数 | ||
* 第五章:寻找和为定值的两个或多个数 | ||
* 第十一章:最长公共子序列(LCS)问题 | ||
* 第二十二章:最短摘要的生成 | ||
* 第二十六章:基于给定的文档生成倒排索引的编码与实践 | ||
* 第二十八章:最大连续乘积子串 | ||
* 第二十九章:字符串编辑距离 | ||
* 第三十章:字符串转换成整数 | ||
* 第三十一章:带通配符的字符串匹配问题 | ||
* 第三十二章:最小操作数 | ||
* 第三十三章:木块砌墙 | ||
* 第三十五章:完美洗牌算法 | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
##preprocess | ||
##as all links of image are ended by ?raw=true, which make pandoc failed to read image, | ||
##this would deal with it | ||
echo "preprocessing files" | ||
sed -i "" -e 's/!\[\](\(.*\)\?raw=[a-z]*\(.*\))/![](\1\2)/g' -e 's/!\[\](\(.*\)\?raw=[a-z]*\(.*\))/![](\1\2)/g' ../zh/*.md | ||
echo "generating TAOP_July.epub" | ||
pandoc -S -o TAOP_July.epub metadata.yaml ../zh/*.md --highlight-style haddock | ||
echo "reverse changes" | ||
git reset --hard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: | ||
- type: main | ||
text: The Art of Programming By July | ||
- type: subtitle | ||
text: somestuff | ||
creator: | ||
- role: author | ||
text: July | ||
contributor: | ||
- role: author | ||
text: co sdfds | ||
date: 2014 | ||
language: zh_CN | ||
description: | ||
cover-image: TAOP.png | ||
stylesheet: style.css | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* This defines styles and classes used in the book */ | ||
body { margin: 5%; text-align: justify; font-size: medium; } | ||
code { font-family: monospace; font-size: small;} | ||
h1 { text-align: left; } | ||
h2 { text-align: left; } | ||
h3 { text-align: left; } | ||
h4 { text-align: left; } | ||
h5 { text-align: left; } | ||
h6 { text-align: left; } | ||
h1.title { } | ||
h2.author { } | ||
h3.date { } | ||
ol.toc { padding: 0; margin-left: 1em; } | ||
ol.toc li { list-style-type: none; margin: 0; padding: 0; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdio.h> | ||
#include <assert.h> | ||
#include <string.h> | ||
|
||
char *mystrcpy(char* dest, const char *src) | ||
{ | ||
assert(dest != NULL && src != NULL); | ||
assert(dest < src || strlen(src) < (unsigned int)(dest - src)); | ||
if (src == dest) | ||
return dest; | ||
char *ret = dest; | ||
while('\0' != (*dest++ = *src++)) | ||
; | ||
return ret; | ||
} | ||
|
||
int main() | ||
{ | ||
char dest[1024]; | ||
char src[] = "abcdef"; | ||
mystrcpy(dest, src); | ||
printf("%s\n", dest); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
CC = g++ | ||
CPPFLAGS = -Wall | ||
all: chapter01 chapter03 chapter06 chapter25 | ||
|
||
FILE_SUFFIX = cpp | ||
|
||
chapter01: chapter01.cpp | ||
$(CC) $(CPPFLAGS) chapter01.cpp -o chapter01 | ||
SRCS := $(wildcard *.$(FILE_SUFFIX)) | ||
EXES := $(patsubst %.$(FILE_SUFFIX),%,$(SRCS)) | ||
|
||
chapter03: chapter03.cpp | ||
$(CC) $(CPPFLAGS) chapter03.cpp -o chapter03 | ||
all:$(EXES) | ||
|
||
chapter06: chapter06.cpp | ||
$(CC) $(CPPFLAGS) chapter06.cpp -o chapter06 | ||
|
||
chapter25: chapter25.cpp | ||
$(CC) $(CPPFLAGS) chapter25.cpp -o chapter25 | ||
$(EXES): % : %.$(FILE_SUFFIX) | ||
$(CC) $(CPPFLAGS) $< -o $@ | ||
|
||
clean: | ||
rm chapter01 | ||
rm chapter03 | ||
rm chapter06 | ||
rm chapter25 | ||
rm -rf $(EXES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
class Chapter1 { | ||
|
||
// Version 1 | ||
public void leftShiftV1 (char[] s, int m) { | ||
while (m > 0) { | ||
leftShiftOne(s); | ||
m--; | ||
} | ||
} | ||
|
||
private void leftShiftOne (char[] s) { | ||
int len = s.length; | ||
int i = 0; | ||
char c = s[0]; | ||
while (i < len - 1) { | ||
s[i] = s[i + 1]; | ||
i++; | ||
} | ||
s[len - 1] = c; | ||
} | ||
|
||
|
||
// Version2 | ||
public void leftShiftV2(char[] s, int m) { | ||
int len = s.length; | ||
m = m % len; | ||
reverse(s, 0, m - 1); | ||
reverse(s, m, len - 1); | ||
reverse(s, 0, len - 1); | ||
} | ||
|
||
private void reverse (char[] s, int from, int to) { | ||
while(from < to) { | ||
char c = s[from]; | ||
s[from] = s[to]; | ||
s[to] = c; | ||
from++; | ||
to--; | ||
} | ||
} | ||
|
||
public static void main (String[] args) { | ||
Chapter1 chapter1 = new Chapter1(); | ||
|
||
String str = "asdfghjkl"; | ||
System.out.println("Original String:"); | ||
System.out.println(str); | ||
char[] arr1 = str.toCharArray(); | ||
char[] arr2 = str.toCharArray(); | ||
|
||
chapter1.leftShiftV1(arr1, 2); | ||
chapter1.leftShiftV2(arr2, 2); | ||
|
||
System.out.println("Left shift V1:"); | ||
System.out.println(new String(arr1)); | ||
System.out.println("left Shift V2:"); | ||
System.out.println(new String(arr2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Chapter2 { | ||
public static void main (String[] args) { | ||
System.out.println("QuickSort and Compare:"); | ||
ICompare sortAndCompare = new SortAndCompare(); | ||
System.out.println(sortAndCompare.compare("ABCDEFGHLMNOPQRS", "DCGSRQPOM")); | ||
System.out.println(sortAndCompare.compare("ASDF", "GHJK")); | ||
|
||
System.out.println("Counting Sort and Compare:"); | ||
ICompare countAndCompare = new CountAndCompare(); | ||
System.out.println(countAndCompare.compare("ABCDEFGHLMNOPQRS", "DCGSRQPOM")); | ||
System.out.println(countAndCompare.compare("ASDF", "GHJK")); | ||
|
||
System.out.println("Using HashTable:"); | ||
ICompare hashTableCompare = new HashTableCompare(); | ||
System.out.println(hashTableCompare.compare("ABCDEFGHLMNOPQRS", "DCGSRQPOM")); | ||
System.out.println(hashTableCompare.compare("ASDF", "GHJK")); | ||
|
||
System.out.println("Using Prime Product and Mode:"); | ||
ICompare primeCompare = new PrimeCompare(); | ||
System.out.println(primeCompare.compare("ABCDEFGHLMNOPQRS", "DCGSRQPOM")); | ||
System.out.println(primeCompare.compare("ASDF", "GHJK")); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class CountAndCompare implements ICompare { | ||
@Override | ||
public boolean compare(String longString, String shortString) { | ||
int posLong = 0, posShort = 0; | ||
longString = countSort(longString); | ||
shortString = countSort(shortString); | ||
while (posLong < longString.length() && posShort < shortString.length()) { | ||
while (posLong < longString.length() && longString.charAt(posLong) < shortString.charAt(posShort)) { | ||
posLong++; | ||
} | ||
|
||
if (posLong >= longString.length() || longString.charAt(posLong) != shortString.charAt(posShort)) { | ||
return false; | ||
} else { | ||
posShort++; | ||
} | ||
} | ||
return posShort == shortString.length(); | ||
} | ||
|
||
private String countSort(String str) { | ||
int[] help = new int[26]; | ||
for (int i = 0; i < str.length(); i++) { | ||
int index = str.charAt(i) - 'A'; | ||
help[index]++; | ||
} | ||
StringBuilder buf = new StringBuilder(); | ||
for (int i = 0; i < 26; i++) { | ||
for (int j = 0; j < help[i]; j++) { | ||
buf.append((char)(i + (int)'A')); | ||
} | ||
} | ||
return buf.toString(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.