Skip to content

Instantly share code, notes, and snippets.

View caoxudong's full-sized avatar
💭
coding,talking

caoxudong caoxudong

💭
coding,talking
View GitHub Profile
@caoxudong
caoxudong / remove_elem_from_array.c
Created November 5, 2012 10:36
给一个数组和一个值,从数组中删除这个指定的值的所有出现,并且返回新的数组的长度。
/**
* 给一个数组和一个值,从数组中删除这个指定的值的所有出现,并且返回新的数组的长度。
* size_t remove_elem(T* array, size_t len, T elem) {}。
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]){
@caoxudong
caoxudong / KMP1.java
Created November 5, 2012 10:41
KMP算法的实现
public class KMP1 {
public static int kmp1(String pattern, String src){
int srcLength = src.length() ;
int patternLength = pattern.length() ;
int index = -1 ;
int count = 0 ;
for(int i = 0 ; i < srcLength - 1 ;){
count = 0 ;
for(int j = 0 ; (j < patternLength ) && (i < srcLength) ; j++){
if(src.charAt(i) == pattern.charAt(j)){
@caoxudong
caoxudong / Output
Created November 6, 2012 02:48
ZZ. @老赵 生成一段Typoglycemia文本.Typoglycemia是个新词,描述的是人们识别一段文本时的一个有趣的现象:只要每个单词的首尾字母正确,中间的字母顺序完全打乱也没有关系,照样可以正常理解。
Original String:
I couldn't believe that I could actually understand what I was reading:
the phenomenal power of the human mind. According to a research team at Cambridge University,
it doesn't matter in what order the letters in a word are, the only important thing is that the
first and last letter be in the right place. The rest can be a total mess and you can still read
it without a problem. This is because the human mind does not read every letter by itself, but the
word as a whole. Such a condition is appropriately called Typoglycemia. Amazing, huh? Yeah and you
always thought spelling was important.
Converted String:
@caoxudong
caoxudong / testSidCountInPlayerP2PStats.py
Created November 14, 2012 07:16
测试播放器P2P统计中对sid个数的统计,这里的问题是,所有日志中sid集合的个数与warning类型的日志中sid集合个数不同
#!/usr/bin/env python
'''
This script is used to test sid stats in player p2p stats.
Created on 2012-11-14
@author: caoxudong
'''
@caoxudong
caoxudong / TestString.java
Created January 18, 2013 12:14
关于字符串拼接的一个记录。以前没有注意,null与字符串拼接时会多出一个"null"字符串来。
package test.java.lang.string;
import java.util.regex.Pattern;
public class TestString {
public static void main(String[] args) {
String a = null;
a += "a";
@caoxudong
caoxudong / solution1.py
Last active December 15, 2015 04:39
Project Euler - Problem 9 A Pythagorean triplet is a set of three natural numbers, a<b<c, for which, a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
n = 1000
a = 1
b = 1
c = 1
result = 0
while a < n:
b = a + 1
while b < n:
c = b + 1
@caoxudong
caoxudong / convert1.cpp
Created May 30, 2013 12:59
字符串与数字的转换
/**
* 将16进制字符串转换为对应的字节数组。
* 其中,字符串中每两个字节作为结果数组中的一个字节的内容的16进制表示
* /
char peerId[] = {"0fd5081f306494b7b290c2ef9594c56613212b4945d8ece8fcb832ad1d33a169"};
std::string realPeerId;
char tempCh = 0;
for (char* ch = peerId; *ch != 0; ch += 2) {
@caoxudong
caoxudong / cstring2pchar.cpp
Created June 2, 2013 13:39
CString 2 char*
//用于将cstring转为char*
CString peerIdCString = _T("e0f4111df2a7d6bf591619884e353452bccb26c5a8ffa18079061d16f533fe1e");
USES_CONVERSION;
char* buffer = T2A(peerIdCString);
@caoxudong
caoxudong / reverse_single_linked_list.py
Last active December 19, 2015 13:49
reverse a singly linked list
#!/usr/bin/env python
class Node:
data = None
next = None
def __init__(self,lndata):
self.data=lndata
class List:
size = 0
@caoxudong
caoxudong / hanoi.py
Created July 10, 2013 10:25
汉诺塔
#!/usr/bin/env python
import os
def hanoiRecursively(fromBar, intermediateBar, toBar, number):
if number == 1:
print 'move 1 from ' + fromBar + ' to ' + toBar
else:
hanoiRecursively(fromBar, toBar, intermediateBar, number - 1)
print 'move ' + str(number) + ' from ' + fromBar + ' to ' + toBar