Skip to content

Instantly share code, notes, and snippets.

def odd(n):
return n%2
li=[1,2,3,5,9,10,256,-3]
filter(odd,li) //输出[1,3,5,9,-3]
def double(n):
return n*2
li=[5,'a',(2,'b')]
map(double,li) //返回[10,'aa',(2,'b',2,'b')]
#! /usr/bin/env python
#coding=utf-8
def mean(sorted_list):
if not sorted_list:
return ([],[])
big=sorted_list[-1]
small=sorted_list[-2]
big_list,small_list=mean(sorted_list[:-2])
big_list.append(small)
#include "highgui.h"
#include "cv.h"
#include <stdio.h>
#define MAX_CORNERS 50
int capture_data()
{
CvCapture* capture;
IplImage* frame;
@shihongzhi
shihongzhi / pig.cpp
Created October 28, 2010 02:40
析构函数和构造函数的调用过程
#include <iostream>
using namespace std;
struct Pig
{
Pig()
{
call();
}
@shihongzhi
shihongzhi / split+foreach.cpp
Created October 28, 2010 04:07
stringSplit的实现,以及foreach宏
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//无法使用typeof,因为这是gcc的扩展
//#define foreach(container,it) for(typeof((container).begin()) it=(container).begin();it!=(container).end();++it)
#define foreach(type,container,it) for(type::iterator it=(container).begin();it!=(container).end();++it)
//http://zhedahht.blog.163.com/blog/static/25411174200732711051101/ 我是倒这过来做的
#include <stdio.h>
void print_sequence(int small,int big)
{
int i;
for(i=small;i<=big;i++)
printf("%d ",i);
printf("\n");
}
#include <stdio.h>
#define BITNUMBER 32 //int占4个字节
#define N 32000
int a[N/BITNUMBER+1];
void set(int i)
{
a[i/BITNUMBER]|=1<<(i%BITNUMBER);
#include <stdio.h>
#include <stdlib.h>
#define BITNUMBER 32
#define N 10000000
#define random(x) rand()%x
int a[N/BITNUMBER+1];
void set(int i)
/*2010/11/18 shihongzhi
* 实现了printf,itoa,ftoa
* todo:%f的自定义小数点没有实现
*/
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
const double eps=1e-12;