在命令行里运行.py 文件 跟 直接双击运行的差别

环境:本机同时安装了python27 跟 python 25 我的机器出现了这种情况 cmd: >>> from distutils.sysconfig import get_python_lib >>> print get_python_lib() C:\python27\Lib\site-packages 其运行的版本也是python 2.7 双击运行文件的结果 G:\python\cocos\pyglet>testpath.py C:\Python25\Lib\site-packages 其运行版本为 python 2.5 修改注册表,环境变量均...
默认分类 | 2012-12-16 20:13 | 阅读 8883 次 | 评论 0 条

反转字符串

#include <iostream>#include <cstring>using namespace std;int main(){ //源字符串 char str[100]; cin.get(str, 100); //申请目标字符串的空间 size_t strLen = strlen(str); char *des = new char[strLen + 1]; //源字符串上一次空格的位置 size_t lastIndex = 0; for (size_t i = 0; i <= strLen; ++i) { ...
默认分类 | 2012-05-17 23:34 | 阅读 1523 次 | 评论 0 条

素数环 python递归求解

#-*- coding: gbk -*-#素数环def IsPrimeNum(num): for i in range(2, num): if num % i == 0: return False return True def GetPrimeDic(n): Dic = {} for i in range(1, n+1): Dic[i] = [] for i in range(1, n+1, 2): #even number for j in range(2...
默认分类 | 2012-05-12 06:41 | 阅读 3397 次 | 评论 0 条

计算器类升级版

#include "stdafx.h"#include<iostream>#include<string>#include<sstream>using namespace std;class Computer{ double result;//保存运算结果 istringstream expr; //保存表达示 int paren; /*'(' paren加1,')'paren减1。一旦paren为负时就肯定是输入有错,运算全部结束后其值不为零也是出错。可以增加一个小类来做为paren的类型*/protected: int getSign();//...
默认分类 | 2011-04-24 09:03 | 阅读 1578 次 | 评论 1 条

红黑树的实现

//Rbtree.h#ifndef RBTREE#define RETREEtypedef int type;class Rbtree{ enum COLOR{RED,BLACK}; typedef struct Node { Node(); Node(type k); /*Node(const Node&amp;);*/ void* operator new(size_t size) { static int p = 0; static...
默认分类 | 2011-04-20 15:09 | 阅读 1332 次 | 评论 0 条

一个简单的计算器类

#include<iostream>#include<string>using namespace std;class Computer{ double result;//保存运算结果 int index; //保存expr的下标,index只会增大或者不变,不可能减少 string expr; //保存表达示 int paren; /*'(' paren加1,')'paren减1。一旦paren为负时就肯定是输入有错,运算全部结束后其值不为零也是出错。可以增加一个小类来做为paren的类型*/protected: char getSign...
默认分类 | 2011-04-17 16:46 | 阅读 1488 次 | 评论 0 条

用自动机解决字符串的匹配问题

#include<iostream>using namespace std;int jmpoftable[100][256];void Greattable(const char* str, int lenght)//跳转表的建立{ int i = 0; for(const char *p = str; i<lenght; ++p,++i) { jmpoftable[i][*p] = i+1; } for(int j = 1; j <= i; ++j) { int k = 0; while(str[...
默认分类 | 2011-03-17 08:59 | 阅读 1402 次 | 评论 0 条

排列生成算法

#include<iostream>#include<sstream>#include<algorithm>using namespace std;int main(){ int array[] = {0,1,2,3,4,5,6,7,8,9,10}; int size = sizeof(array)/sizeof(int); int n; cin >> n; int* *index = new int*[size]; for(int i = 0; i < size; ++i) index[i] = array+i; int j ...
默认分类 | 2010-12-24 15:26 | 阅读 1151 次 | 评论 0 条

用递归拆分一个数

#include<iostream>using namespace std;int *arr;int n;void print(){ cout << n << " = " << arr[0]; int i = 1; while(arr[i]) cout << " + " << arr[i++]; cout << endl;}void process(int arr[], int max, int n)//n为剩余值,max为当前位置可以为最大的数。{ arr[0] = max < n ? max : n; if(n == 0) ...
默认分类 | 2010-10-12 09:11 | 阅读 981 次 | 评论 0 条

递归打印菱形

#include<iostream>using namespace std;void printchar(int n, char ch){ for(int i = 0; i != n; ++i) cout << ch;}void fun(int i, int j, int n){ printchar(i,' '); printchar(j,'*'); cout << endl; if(j<n) { fun(i-1,j+2,n); printchar(i,' '); printchar(j,'*')...
默认分类 | 2010-10-12 09:09 | 阅读 1262 次 | 评论 0 条

Win32 控制台应用程序清屏函数

/* Standard error macro for reporting API errors */ #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}void cls( HANDLE hConsole ){ COORD coordScreen = { 0, 0 }; /* here's where we'll home the ...
默认分类 | 2010-10-05 11:10 | 阅读 2947 次 | 评论 0 条

组合生成算法

#include<iostream>using namespace std;void print(const int A[], const int B[], int Bn){ for (int i = 0; i != Bn; ++i) cout << A[*(B+i)];}bool fun(int B[], int Bn, int An)//处理进位{ int x = Bn-1; while(B[x] > x+An-Bn) { if(x == 0) return false; B[x-1] += 1; --x...
默认分类 | 2010-10-01 14:04 | 阅读 1482 次 | 评论 1 条

声明,定义,初始化及赋值

关于声明,定义,初始化及赋值。//file 1int a;//定义:声明一个int类型的变量a,并为其分配存储空间,a的值为随机值(这块存储空间上原先的值)。//file 2extern int a;//声明:声明一个int类型的变量a,但并没有分配存储空间,诉编译器a是在别的地方(文件)定义。/*************end********************/int a = 0;//初值化(初始化还能分为直接初始化和复制初始化)int b;b = 0;//赋值/************************************/int a(0);//直接初始化int b ...
默认分类 | 2010-06-27 15:18 | 阅读 1039 次 | 评论 0 条

虚函数和建构函数

《C++语言的设计和演化》219页。虚函数和建构函数。 基本的设计要点:直到对一个对象的建构函数的运行结束之前,这个对象就一直像一个正在建造之中的建筑物:你必须忍受结构没有完工所带来的各种不便,常常需要依靠临时性的脚手架,必须时时当心在与危险环境相处时的各种问题。一旦建构函数返回,编译程序和用户就都可以假定构造完成的对象能够使用了。 /*建构函数是建立起一个环境,使其他成员函数在其中操作。D&amp;E p219*/#include<iostream.h>class B{public: int b; virtual void f();//1. void f(); 2. v...
浏览30011次