Skip to content

Commit

Permalink
Merge pull request julycoding#1 from julycoding/master
Browse files Browse the repository at this point in the history
2014-01-14
  • Loading branch information
cpcs committed Jan 14, 2014
2 parents 1106ffb + 724a1ba commit df7b62a
Show file tree
Hide file tree
Showing 53 changed files with 1,539 additions and 2,995 deletions.
20 changes: 9 additions & 11 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# About
The 'Art Of Programming' project is a result of a well-known Chinese blog focuses on classic programming problems. Ever since October 2010, the blog receives over 5.5 million unique visits with an incredible amount of positive feedbacks. Due to its popularity, the author (July) can no longer keep up with growing number of question and decided to branch out and open source this project so that everyone contribute.
The 'Art Of Programming' project is the result of a well-known Chinese blog that focuses on classic programming problems. Since October 2010, the blog received over 5.5 million unique visits with an incredible amount of positive feedbacks. Due to its popularity, the author (July) could no longer keep up with the growing number of question, so he decided to branch out and open source this project so everyone can contribute.

An English version is also provided to collaborate with non-Chinese speakers.
An English version is also being provided so non-Chinese speakers can also contribute.

#
看过[结构之法算法之道blog](http://blog.csdn.net/v_july_v)的朋友可能知道,从2010年10月起,[July](http://weibo.com/julyweibo)开始整理一个微软面试100题的系列,他在整理这个系列的过程当中,越来越强烈的感觉到,可以从那100题中精选一些更为典型的题,每一题详细阐述成章,不断优化,于此,便成了程序员编程艺术系列。
Expand All @@ -11,26 +11,24 @@ An English version is also provided to collaborate with non-Chinese speakers.
为了方便大家更好的改进、优化编程艺术系列,特把原来博客上的系列文章同步到此,邀请各位一起协作:若发现本编程艺术系列任何问题、错误、bug,或可以优化的每一段代码,欢迎随时贡献。

#
* [中文目录](https://github.com/nateriver520/The-Art-Of-Programming-By-July/blob/master/ebook/zh/preface.md) Enhancement in progress
* [English Contents](https://github.com/nateriver520/The-Art-Of-Programming-By-July/blob/master/ebook/en/preface.md) Translation in progress
* [中文目录](ebook/zh/Readme.md) Enhancement in progress
* [English Contents](ebook/en/Readme.md) Translation in progress


#
* 添补剩下的章节,即把博客上的原文[程序员编程艺术第一~三十八章](http://blog.csdn.net/v_july_v/article/details/17303459)同步移到本github上,请参考本书[中文目录](https://github.com/nateriver520/The-Art-Of-Programming-By-July/blob/master/ebook/zh/preface.md)未完成的章节
* 添补剩下的章节,即把博客上的原文[程序员编程艺术第一~三十八章](http://blog.csdn.net/v_july_v/article/details/17303459)同步移到本github上,请参考本书[中文目录](ebook/zh/Readme.md)未完成的章节
* 指正 bug
* 优化原有代码,可以直接在原代码上进行修改优化
* 优化原文章上的C/C++ 代码,可以添加在原代码的后面,或者放到[ebook/code](ebook/code/)文件夹内
* 添加其它语言如Java、python、go 的代码,放在[ebook/code](ebook/code/)文件夹内
* 重绘所有的图片:https://github.com/julycoding/The-Art-Of-Programming-by-July/issues/80
* 若添加其它语言的代码,勿直接添加在原文上,可以放在 ebook/code 的代码文件夹内
* 翻译成英文版,参考[中文目录](https://github.com/nateriver520/The-Art-Of-Programming-By-July/blob/master/ebook/zh/preface.md),把翻译后的文章编辑到这[English Version](https://github.com/nateriver520/The-Art-Of-Programming-By-July/blob/master/ebook/en/preface.md),注:不必逐字翻译,精简大气即可(如有兴趣翻译,请到这里领取感兴趣的章节翻译:https://github.com/julycoding/The-Art-Of-Programming-by-July/issues/84 )
* 翻译成英文版,参考[中文目录](ebook/zh/Readme.md),把翻译后的文章编辑到这[English Version](ebook/en/Readme.md),注:不必逐字翻译,精简大气即可(如有兴趣翻译,请到这里领取感兴趣的章节翻译:https://github.com/julycoding/The-Art-Of-Programming-by-July/issues/84 )
* 自己主导续写新的章节,如第三十九章;
* 任何你想做的事情。

你可以做以上任何一件或几件事情,如遇到任何问题或疑惑,咱们可以随时讨论:
<https://github.com/julycoding/The-Art-Of-Programming-by-July/issues?state=open>

#
为示鼓励,所有贡献了本 github 的朋友,可以随时向 July 索取他博客内所有博文集锦的最新CHM文件,或任何一个系列的最新PDF或WORD。
为示鼓励,所有贡献了本 github 的朋友,可以随时向 July 索取他博客内所有博文集锦的最新CHM文件,或任何一个系列的最新PDF或WORD,以此感谢所有贡献的朋友:https://github.com/julycoding/The-Art-Of-Programming-by-July/graphs/contributors ,并非常期待你的加入,thanks

孤军奋战的时代早已远去,我们只有团结起来,才能帮助到更多更无数的人。[@研究者July](http://weibo.com/julyweibo),始于二零一三年十二月十四日。

最后, 感谢所有贡献的朋友,并非常期待你的加入:https://github.com/julycoding/The-Art-Of-Programming-by-July/graphs/contributors
50 changes: 50 additions & 0 deletions ebook/build/README.md
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)问题
* 第二十二章:最短摘要的生成
* 第二十六章:基于给定的文档生成倒排索引的编码与实践
* 第二十八章:最大连续乘积子串
* 第二十九章:字符串编辑距离
* 第三十章:字符串转换成整数
* 第三十一章:带通配符的字符串匹配问题
* 第三十二章:最小操作数
* 第三十三章:木块砌墙
* 第三十五章:完美洗牌算法

Binary file added ebook/build/TAOP.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions ebook/build/generate.sh
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
18 changes: 18 additions & 0 deletions ebook/build/metadata.yaml
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
...
14 changes: 14 additions & 0 deletions ebook/build/style.css
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; }
24 changes: 24 additions & 0 deletions ebook/code/cpp/chapter04.cpp
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;
}
21 changes: 7 additions & 14 deletions ebook/code/cpp/makefile
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)
57 changes: 27 additions & 30 deletions ebook/code/go/chapter25.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,34 @@

package main

import (
"fmt"
)

func main() {
var data []int = []int{1, 3, 4, 5, 8, 20}
fmt.Printf("result is %d \n", binarySearch(data, 3))
fmt.Printf("result is %d \n", binarySearch(data, 2))
fmt.Printf("result is %d \n", binarySearch(data, 20))
import "fmt"

func binarySearch(data []int, value int) int {
var left int = 0
var right int = len(data) - 1
var middle int

for left <= right {
middle = left + (right-left)/2

if data[middle] > value {
right = middle - 1
}

if data[middle] < value {
left = middle + 1
}

if data[middle] == value {
return middle
}
}
return -1
}

func binarySearch(data []int, value int) int {
var left int = 0
var right int = len(data) - 1
var middle int

for left <= right {
middle = left + (right-left)/2

if data[middle] > value {
right = middle - 1
}

if data[middle] < value {
left = middle + 1
}

if data[middle] == value {
return middle
}
}
return -1
func main() {
var data []int = []int{1, 3, 4, 5, 8, 20}
fmt.Printf("result is %d \n", binarySearch(data, 3))
fmt.Printf("result is %d \n", binarySearch(data, 2))
fmt.Printf("result is %d \n", binarySearch(data, 20))
}
59 changes: 59 additions & 0 deletions ebook/code/java/chapter1/Chapter1.java
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));
}
}
24 changes: 24 additions & 0 deletions ebook/code/java/chapter2/Chapter2.java
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"));

}
}
37 changes: 37 additions & 0 deletions ebook/code/java/chapter2/CountAndCompare.java
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();
}


}
Loading

0 comments on commit df7b62a

Please sign in to comment.