求最大网络流的C++实现(利用广度优先遍历的思想)基本思想:利用广度优先遍历的思路,从一个可行流(一般取零流)开始,不断进行标号过程和调整过程,直到找不到起点到终点的可增广路径为止。1、标号过程在这个工程中,网络上的点分为已标号点和未标号点。将起始点标号,其他刚开始未标号。从起始点开始,利用广度优先算法进行遍历,找到一个未标号点时,看临接的标号点与之是正向边……继续阅读 » 6年前 (2021-03-24) 1892浏览 2893个赞
Base64编码在邮件中最为常见,呵呵,因为我最近就是在做邮箱报警,SMTP验证就是Base64编码用户名和密码进行验证的,并且图片为附件也是要转换成base64编码的数据,然后再发送的。该编码使用64个明文来编码任意的二进制文件,它里面只使用了A-Z,a-z,0-9,+,/这64个字符。编码里面还有“=”号啊,不过等号不属于编码字符,而是填充字符。 ……继续阅读 » 6年前 (2021-03-24) 2227浏览 117个赞
C++清空或删除文件夹//清空log文件夹void CPMAgentManageDlg::DeleteFolder(CString sPath){ CFileFind ff; BOOL bFound; bFound = ff.FindFile(sPath + "\\*.*"); while(bFound) { bF……继续阅读 » 6年前 (2021-03-24) 1626浏览 905个赞
简单Tcp编程范例,一个C++实现的简单的C/S程序//InitSock.h#pragma once#include <WinSock2.h>#pragma comment(lib,"WS2_32")class CInitSock{public: CInitSock(BYTE minorVer = 2,BY……继续阅读 » 6年前 (2021-03-24) 2561浏览 1401个赞
题目:输入n个整数,输出其中的k个最小数。例如:例如输入1,2,3,4,5,6,7和8这8个数字,则最小的4个数字为1,2,3和4。解题思路:当然,方法最简单的就是对这n个整数都进行排序操作,但这种方法的时间复杂度尤其的高。因此,我采用了,用另外k个空间,以换取时间的方法 。每次从输入的n个整数中读入一个数。如果数组中已经插入的元素少于k个,则将读入的整数……继续阅读 » 6年前 (2021-03-24) 3326浏览 179个赞
C++ 通过堆栈实现进制转换的代码#include<iostream.h>#define ten 10#define hundred 100struct sqstack{ int* p; int top; int size;};void pop(sqstack &q,int &e){ e=q.p[--q……继续阅读 » 6年前 (2021-03-24) 3001浏览 2749个赞
C++ Unicode(char*)转UTF8的代码1.这里只是单个unicode字符的转换,字符串转换的话需要遍历整个字符串,可用std::string的append添加.2.如果只是2字节宽的unicode,只需要unicode_char_length = 2就行了。转自:http://blog.csdn.net/infoworld/article/de……继续阅读 » 6年前 (2021-03-24) 1802浏览 1328个赞
C++编写的页面淘汰算法FIFO//FIFO#include<iomanip>#include<iostream>using namespace std;void discard(int Array[][19],int pagenumber[],int page[],int max);int FIFO(int page……继续阅读 » 6年前 (2021-03-24) 1940浏览 546个赞
C++编写的页面淘汰算法LRU转自:http://blog.csdn.net/caidadong/article/details/8453483//FIFO#include<iostream>#include<iomanip>using namespace std;void discard(int Array[][19]……继续阅读 » 6年前 (2021-03-24) 2911浏览 2791个赞
C++编写的页面淘汰算法OPT转自:http://blog.csdn.net/caidadong/article/details/8453432//OPT/*算法思想:1.求出当前页架中那个是可以置换的,这就要求分析匹配当前页架中的页面和访问序列, 看访问序列中接下来页面中最近访问的位置是哪,然后比较大小。*/#include<ios……继续阅读 » 6年前 (2021-03-24) 2190浏览 313个赞
C++实现的计数排序与基数排序转自:http://blog.csdn.net/bruce_zeng/article/details/8452964 这里的两个排序的期望运行时间都是O(n),应该是到目前为止时间复杂度最低的了。计数排序计数排序假设n个输入元素的每一个都是介于0到K之间的……继续阅读 » 6年前 (2021-03-24) 3201浏览 1623个赞
C++删除字符串中特定的字符//处理string类型的方法del_sp(string &str)待测试//处理C-Style的方法可用,可以考虑将该方法改写为void del_ch(char *src , char ch),使其更加通用化。#include <iostream>#include <string>u……继续阅读 » 6年前 (2021-03-24) 1821浏览 1008个赞
C++ 读取堆栈trace并写入控制台StackTrace *st = new StackTrace(true);// true means get line numbers.for ( int i = 0; i < st->FrameCount; ++i ) { StackFrame *sf = st->GetFrame(i……继续阅读 » 6年前 (2021-03-24) 2155浏览 673个赞
C++双向链表代码,使用了oop技术//An example of a simple double linked list using OOP techniques#include <iostream>using namespace std; struct Node{ double value; Node *N,*P; ……继续阅读 » 6年前 (2021-03-24) 1534浏览 285个赞
C++ Failproof xor 加解密源代码/* All of the XOR encryption algorithms I encountered on the web were faulty on * some keys/inputs using binary read & write both for files and cha……继续阅读 » 6年前 (2021-03-24) 2618浏览 1905个赞
一个模板化的C++堆栈类//An example of using templated class to create stack depends on underlying array.#include<iostream>#include<cstdlib>#define default_value 10using na……继续阅读 » 6年前 (2021-03-24) 3486浏览 1804个赞
一个模板化C++队列类//The following program shows OOP style technique to create queue buffer (FIFO) using class template #include<iostream>#include<cstdlib>#define defa……继续阅读 » 6年前 (2021-03-24) 3316浏览 2986个赞
一个C++实现的简单哈希表(hashtable)范例//A simple example of hashtable#include <iostream>#include <cstdlib>#include <cstring>#include <iomanip>#define SIZE_KEY ……继续阅读 » 6年前 (2021-03-24) 2333浏览 2901个赞
windows下把ntstatus转换成win32 error的C++代码/* * This is an alternative to the RtlNtStatusToDosError() * function in ntdll.dll. It uses the GetOverlappedResult() * function in kern……继续阅读 » 6年前 (2021-03-24) 3204浏览 1647个赞
一个C++堆栈类,已经模板化,支持泛型//An example of using templated class to create stack depends on underlying array.#include<iostream>#include<cstdlib>#define default_value 10u……继续阅读 » 6年前 (2021-03-24) 3563浏览 407个赞
一个模板化的C++队列类,支持泛型//The following program shows OOP style technique to create queue buffer (FIFO) using class template #include<iostream>#include<cstdlib>#defin……继续阅读 » 6年前 (2021-03-24) 2846浏览 2316个赞
python可以通过open函数打开文件,通过close函数关闭文件#!/usr/bin/python# Open a filefo = open("foo.txt", "wb")print "Name of the file: ", fo.name# Close opend fi……继续阅读 » 6年前 (2021-03-22) 2746浏览 1213个赞
一个python自定义的加密解密函数,下面的代码实现了对字符串的加密盒解密,调用简单def encrypt(key, s): b = bytearray(str(s).encode("gbk")) n = len(b) # 求出 b 的字节数 c = bytearray(n*2) j = 0 ……继续阅读 » 6年前 (2021-03-22) 1700浏览 1469个赞
python通过zlib压缩和解压缩字符串,可以自定义压缩级别,级别越高压缩的约厉害,效率要低一些import zlibcompressedString = zlib.compress(originalString, 9) # 采用9级压缩decompressedString = zlib.decompress(compressedStrin……继续阅读 » 6年前 (2021-03-22) 2242浏览 1122个赞
python自定义isnumber函数判断字符串是否为数字''' isnumeric.pytest a numeric string s if it's usable for int(s) or float(s)'''def isnumeric(s): '&……继续阅读 » 6年前 (2021-03-22) 2961浏览 1801个赞
python不定义函数实现数字增减,原来python还可以这么用,你一定想不到inc = (1).__add__print(inc(4))#5sub = (-1).__radd__print(sub(5))#4……继续阅读 » 6年前 (2021-03-22) 2385浏览 2797个赞
python通过Tkinter显示网络图片''' tk_image_view_url_io.pydisplay an image from a URL using Tkinter, PIL and data_streamtested with Python27 and Python33 by vegaseat 0……继续阅读 » 6年前 (2021-03-22) 2038浏览 235个赞
python通过PyGame绘制图像并保存为图片文件''' pg_draw_circle_save101.pydraw a blue solid circle on a white backgroundsave the drawing to an image filefor result see http://prn……继续阅读 » 6年前 (2021-03-22) 1977浏览 1388个赞
将这段代码放入你的脚本中,类似:urllib.urlretrieve(getFile, saveFile, reporthook=report)第三个参数如下面的函数定义report,urlretrieve下载文件时会实时回调report函数,显示下载进度def report(count, blockSize, totalSize): perc……继续阅读 » 6年前 (2021-03-22) 3097浏览 1448个赞
python-memcache 基本使用方法代码,如果没有安装python-memcached可以先通过easy_install安装:easy_install python-memcached#!/usr/bin/env python import memcache mc = memcache.Client(['127.0.0.1:……继续阅读 » 6年前 (2021-03-22) 2149浏览 311个赞
python链接远程ftp服务器并列出目录下的文件,这段python代码用到了pysftp模块,使用sftp协议,对数据进行加密传输import pysftp srv = pysftp.Connection(host="your_FTP_server", username="your_username",p……继续阅读 » 6年前 (2021-03-22) 3419浏览 132个赞
python通过BeautifulSoup分析网页信息,这段python代码查找网页上的所有链接,分析所有的span标签,并查找class包含titletext的span的内容#import the library used to query a websiteimport urllib2 #specify the url you want to……继续阅读 » 6年前 (2021-03-22) 2300浏览 2751个赞
给定一个1-99之间的数,让用户猜数字,当用户猜错时会提示用户猜的数字是过大还是过小,知道用户猜对数字为止,猜对数字用的次数越少成绩越好。import randomn = random.randint(1, 99)guess = int(raw_input("Enter an integer from 1 to 99: "))……继续阅读 » 6年前 (2021-03-22) 2123浏览 372个赞
os是python用于操作系统级的操作模块,包括获取系统信息,文件及目录操作等import osos.system() #用于执行系统命令os.environ() #返回用户环境信息os.getcwd() #返回当前工作目录os.getgid() #返回当先进程的group idos.getuid() #返回当前进程的用户id……继续阅读 » 6年前 (2021-03-22) 2719浏览 1407个赞
python统计字符串中指定字符出现的次数,例如想统计字符串中空格的数量s = "Count, the number of spaces."print s.count(" ") x = "I like to program in Python"print x.count(&qu……继续阅读 » 6年前 (2021-03-22) 2009浏览 465个赞
下面的python代码通过对各种字符进行随机组合生成一个指定长度的随机密码 python中的string对象有几个常用的方法用来输出各种不同的字符:string.ascii_letters输出ascii码的所有字符string.digits输出 ’……继续阅读 » 6年前 (2021-03-22) 3160浏览 2373个赞
下面的python代码展示python中字典的常用操作,字典在python开发中有着举足轻重的地位,掌握字典操作相当重要#创建一空字典x = {}#创建包含三个项目的字典x = {"one":1, "two":2, "three":3}#访问其中的一个元素x['two……继续阅读 » 6年前 (2021-03-22) 3153浏览 952个赞
python实现的telnet客户端程序,python自带一个telnetlib模块,可以通过其Telnet类实现telnet操作import getpassimport sysimport telnetlib HOST = "hostname" user = raw_input("Enter your rem……继续阅读 » 6年前 (2021-03-22) 2775浏览 145个赞
给定网址,通过这段python代码可以很容易获取域名信息import urlparseurl = "http://www.75271.com"domain = urlparse.urlsplit(url)[1].split(':')[0]print "The domain name of the……继续阅读 » 6年前 (2021-03-22) 1951浏览 2397个赞
这段python代码通过urllib2抓取网页,然后通过简单的正则表达式分析网页上的全部url地址import urllib2import re #connect to a URLwebsite = urllib2.urlopen(url) #read html codehtml = website.read() #use re.fi……继续阅读 » 6年前 (2021-03-22) 2483浏览 909个赞
python通过calendar输出指定年份的全年日历import calendar print "Show a given years monthly calendar" print '' year = int(raw_input("Enter the year")) pri……继续阅读 » 6年前 (2021-03-22) 3047浏览 2287个赞
下面python代码通过urllib2抓取指定的url的内容,并且使用自定义的user-agent,防止网站屏蔽采集器import urllib2 req = urllib2.Request('http://192.168.1.2/') req.add_header('User-agent', '……继续阅读 » 6年前 (2021-03-22) 1941浏览 454个赞
下面的python代码可用于检测字符串,包括是否全部为数字,是否包含数字,是否包含标题单词,是否包含大写字母,是否包含小写字母,是否包含空格,是否以指定的字符开头和结尾。my_string = "Hello World"my_string.isalnum() #检测所有字符是否都是数字my_string.isalpha() ……继续阅读 » 6年前 (2021-03-22) 1745浏览 560个赞
python中列表元素连接方法join的用法 创建列表>>> music = ["Abba","Rolling Stones","Black Sabbath","Metallica"……继续阅读 » 6年前 (2021-03-22) 1797浏览 185个赞
python常用列表(数组)操作演示,包括创建列表,添加新元素,获取列表长度,删除元素,数组翻转,列表排序,在指定位置添加元素,统计某元素出现的次数等等s = ['h','e','l','l','o'] #create a lists.append(&……继续阅读 » 6年前 (2021-03-22) 2812浏览 329个赞