算法设计与分析实验源代码及运行结果(完整版)实用资料_第1页
算法设计与分析实验源代码及运行结果(完整版)实用资料_第2页
算法设计与分析实验源代码及运行结果(完整版)实用资料_第3页
算法设计与分析实验源代码及运行结果(完整版)实用资料_第4页
算法设计与分析实验源代码及运行结果(完整版)实用资料_第5页
已阅读5页,还剩70页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

算法设计与分析实验源代码及运行结果(完整版)实用资料(可以直接使用,可编辑完整版实用资料,欢迎下载)

1.分治法二分检索源代码:算法设计与分析实验源代码及运行结果(完整版)实用资料(可以直接使用,可编辑完整版实用资料,欢迎下载)#includeusingnamespacestd;voidSelectSort(int*pData,intCount{intiTemp;intiPos;for(inti=0;i{iTemp=pData[i];iPos=i;for(intj=i+1;j{if(pData[j]{iTemp=pData[j];iPos=j;}}pData[iPos]=pData[i];pData[i]=iTemp;}}voidmain({intiCount;cout<<"请输入要排序的个数:"<cin>>iCount;intData[2000];cout<<"请输入原始数据:"<for(intk=0;k{cout<<"Data["<cin>>Data[k];}cout<<"排序之前的数据顺序为:"<for(intj=0;j{cout<";}cout<cout<<"排序之后的数据顺序为:"<SelectSort(Data,iCount;for(inti=0;i{cout<}cout<}运行结果截图:2.分治法排序源代码:#include#includeusingnamespacestd;intdivide(int*list,intlow,inthigh{intpivotkey=list[low];while(low<high{while(low<high&&list[high]>=pivotkeyhigh--;list[low]=list[high];while(low<high&&list[low]<=pivotkeylow++;list[high]=list[low];}list[low]=pivotkey;returnlow;}//一次划分;voidsort(int*list,intlow,inthigh{if(low<high{intpivotloc=divide(list,low,high;sort(list,low,pivotloc-1;sort(list,pivotloc+1,high;}}//快速排序算法;intmain({intarry[100];inti;cout<<"Thearrytobesortedare:"<for(i=0;i<100;i++{arry[i]=rand(%100;cout<}sort(arry,0,99;cout<for(i=0;i<100;i++{cout<}return0;}运行结果截图:1.货郎担问题源代码:#include#include#include#defineNUM4usingnamespacestd;intnum=(intpow(2,NUM-1;classsubset{public:boolcontains[NUM-1];//除了开始结点外,包含哪个城市就把相应的contains设置为1;boolis_in(inti{i--;if(contains[i]returntrue;elsereturnfalse;}//判断第i个城市是否在子集中,如果在返回true,否则false;};//所有节点城市的子集。voidset_ct(subset*s,intbegin,intend,intprocess{if(NUM-2==process{s[begin].contains[process]=false;s[end].contains[process]=true;}else{intmiddle=(end+begin/2;inti;for(i=begin;i<=middle;i++s[i].contains[process]=false;set_ct(s,begin,middle,process+1;for(i=middle+1;i<=end;i++s[i].contains[process]=true;set_ct(s,middle+1,end,process+1;}}//用递归的方法初始化子集结点;intcombian(inta,intb{if(b>=0&&a>=b{if(0==b||a==breturn1;else{if(a-b<bb=a-b;//组合数的性质;inti,result=1;for(i=a-b+1;i<=a;i++result*=i;for(i=2;i<=b;i++result/=i;returnresult;}}elsereturn-1;}//组合数(a选b)的计算,数据合法返回正确的值,否则返回-1,intget_h(bool*c,intn{inti,result=0;for(i=0;i<NUM-1;i++{if(i!=n&&c[i]result+=(intpow(2,NUM-2-i;}returnresult;}//计算table_d表的横坐标horizontal,intmain({int**cities=newint*[NUM];//存储个城市之间的代价矩阵int**table_d=newint*[NUM];//存储动态距离表int**table_p=newint*[NUM];//存储动态结点选在表subset*sbst=newsubset[num];//所有城市节点的子集。inti,j,k,temp,horizontal;for(i=0;i<NUM;i++{cities[i]=newint[NUM];table_d[i]=newint[num];table_p[i]=newint[num];for(j=0;j<NUM;j++cin>>cities[i][j];table_d[i][0]=cities[i][0];//初始化距离表的第一列}/*cities[0][0]=32767;cities[0][1]=3;cities[0][2]=6;cities[0][3]=7;cities[1][0]=5;cities[1][1]=32767;cities[1][2]=2;cities[1][3]=3;cities[2][0]=6;cities[2][1]=4;cities[2][2]=32767;cities[2][3]=2;cities[3][0]=3;cities[3][1]=7;cities[3][2]=5;cities[3][3]=32767;for(i=1;i<NUM;i++table_d[i][0]=cities[i][0];*/set_ct(sbst,0,num-1,0;for(j=1;j<num-1;j++{for(i=1;i<NUM;i++{if(!sbst[j].contains[i-1]{table_d[i][j]=32767;for(k=1;k<NUM;k++{if(sbst[j].contains[k-1]{horizontal=get_h(sbst[j].contains,k-1;//计算出此时的table_d的横坐标。temp=cities[i][k]+table_d[k][horizontal];if(temp<table_d[i][j]{table_d[i][j]=temp;//将最短距离存入距离表table_p[i][j]=k;//将选择的结点存入节点表;}}}//对子集中的每一个元素计算各自被选择时的距离,然后选择最少的。}//子集j中不包含i时}//扫描该列的每一行}//逐列扫描;table_d[0][num-1]=32767;for(i=NUM-1;i>0;i--{horizontal=get_h(sbst[num-1].contains,i-1;temp=cities[0][i]+table_d[i][horizontal];if(temp<table_d[0][num-1]{table_d[0][num-1]=temp;table_p[0][num-1]=i;}}cout<<"Theshortestdistanceis:"<cout<<"Thepathis:0->"<";temp=table_p[0][num-1];horizontal=get_h(sbst[num-1].contains,temp-1;for(i=1;i<NUM-1;i++{cout<";temp=table_p[temp][horizontal];horizontal=get_h(sbst[horizontal].contains,temp-1;}cout<<0;return0;}运行结果截图:当各城市距离都相等,比如1时:当输入课件中讨论的数据时:当输入上述矩阵按其主对角线对换后的矩阵的数据时:路径刚好跟上面的相反。2.投资问题源代码:#include#includeusingnamespacestd;#defineN5//工程数;#defineA10//资金总数;intmain({int**g=newint*[N];//NXA的矩阵,存储对工程i投资j万元的利润;int**table=newint*[N+1];//(N+1X(A+1矩阵,存入动态决策表;int**cash=newint*[N];//NXA的矩阵,存储各工程的投资数int*result=newint[N];//记录最终结果,用于输出;inti,j,k,temp;for(i=0;i<N;i++{cash[i]=newint[A];g[i]=newint[A];table[i]=newint[A+1];table[i][0]=0;//table的第一列赋0;}//给各矩阵分配空间;table[N]=newint[A+1];table[N][0]=0;for(i=A;i>0;i--table[0][i]=0;//table第一行赋0;cout<<"Theprofitofj*10000yuaninvesttoprojectiare:"<for(i=0;i<N;i++{for(j=0;j<A;j++{g[i][j]=rand(%5;cout<}cout<}//为了方便,随机给利润矩阵g赋值;cout<for(i=1;i<=N;i++//对每一列:for(j=1;j<=A;j++//对该列的每一个元素{table[i][j]=table[i-1][j];cash[i-1][j-1]=0;for(k=1;k<=j;k++{temp=table[i-1][j-k]+g[i-1][k-1];//有递推关系和前面已经求出的table得出当前的。if(temp>table[i][j]{table[i][j]=temp;cash[i-1][j-1]=k;}//记下在有j万元资金的情况下投资前i个工程的最大利润,同时记录投资工程i的资金到cash中}}temp=A-1;for(i=N-1;i>=0;i--{result[i]=cash[i][temp];temp-=result[i];}//从cash表格中得出最终结果;cout<<"Investmenttoeachprojectare:"<for(i=0;i<N;i++cout<<"Project"<cout<return0;}运行结果截图:百度文库下载器源代码

文件结构 Zlib用于豆丁文档的解压缩,自己网上找开源代码,我也网上下载的,由于文件较多,所以没有贴出来,如果需要,跟帖我可以给链接,DOCIN.CS是支持豆丁网的下载类,由于还不支持V2版本,所以暂时不公开

Global.csusingSystem;usingSystem.Text;usingSystem.Xml;usingSystem.IO;usingzlib;namespaceDocDown{publicclassGlobal{publicclass_DATA_REGEXS{publicstaticreadonlystringURL=@"^((://www\.docin\/p-\d{8}\.html)|(://wenku\.baidu\/view/[0-9a-z]{24}\.html))$";publicstaticreadonlystringDOCIN_DOC_INFO=@"^[\s\S]*playcontent=(\{.*?})[\s\S]*$";publicstaticreadonlystringBAIDU_DOC_INFO=@"^[\s\S]*DOC_INFO=(\{.*?})[\s\S]*$";publicstaticreadonlystringBAIDU_DATA=@"^(\{[\s\S]+?\})[\s\S]*?((CWS|FWS)\t[\s\S]*?)+$";publicstaticreadonlystringBAIDU_DATA_HEADER=@"^(\{[\s\S]+?\})([\s\S]+)$";publicstaticreadonlystringBAIDU_DATA_SWF=@"(CWS|FWS)\t[\s\S]*?(?=(CWS|FWS)\t|$)";}publicclass_DATA_URL_FROMAT{publicstaticreadonlystringBAIDU_DATA_URL_TXT=@"://wenku.baidu/play/{0}?pn={1}&rn={2}";publicstaticreadonlystringBAIDU_DATA_URL_NOT_TXT=@"://ai.wenku.baidu/play/{0}?pn={1}&rn={2}";publicstaticreadonlystringDOCIN_DATA_URL_ONE=@"://file1.yimk/docin_{0}.docin";publicstaticreadonlystringDOCIN_DATA_URL_Next=@"://file1.yimk/docin_{0}_{1}.docin";}publicclass_FILE_PATH{publicstaticreadonlystringTEMP_SMALL_PATH=@"TEMP";publicstaticreadonlystringTEMP_FULL_PATH=@"{0}\TEMP";publicstaticreadonlystringSWF_SMALL_PATH=@"TEMP\{0}.SWF";publicstaticreadonlystringSWF_FULL_PATH=@"{0}\TEMP\{1}.SWF";publicstaticreadonlystringJPG_SMALL_PATH=@"TEMP\{0}.JPG";publicstaticreadonlystringJPG_FULL_PATH=@"{0}\TEMP\{1}.JPG";publicstaticreadonlystringPDF_FULL_PATH=@"{0}\{1}.PDF";publicstaticreadonlystringTXT_FULL_PATH=@"{0}\{1}.TXT";publicstaticreadonlystringDOCIN_PATH=@"TEMP\{0}.DOCIN";publicstaticreadonlystringDOCIN_HEADER=@"TEMP\HEAD.DATA";publicstaticreadonlystringDOCIN_SWF=@"TEMP\SWF.DATA";}publicclass_FILE_ENCODING{publicstaticreadonlyEncodingEN=Encoding.GetEncoding("Windows-1252");publicstaticreadonlyEncodingCN=Encoding.GetEncoding("GB2312");publicstaticreadonlyEncodingFTF8=Encoding.UTF8;}publicclass_JPG_SIZE{publicstaticreadonlyintW=1190;publicstaticreadonlyintH=1684;}publicclass_WORK_STATUS_INFO{publicstaticreadonlystringSTART_WORK="正在下载文库资源文件。。。";publicstaticreadonlystringCREATE_SWF="正在生成SWF文件。。。";publicstaticreadonlystringCONVERT_JPG="正在转换资源文件。。。";publicstaticreadonlystringCREATE_PDF="正在生成PDF文件。。。";publicstaticreadonlystringDOWN_ERROR="下载资源失败,请重新提交任务。";publicstaticreadonlystringSUCCESS="任务已完成。";publicstaticreadonlystringBUSY="处理中。。。";publicstaticreadonlystringSTART="开始";publicstaticreadonlystringURL_ERROR="文库地址解析错误,请确认文库地址的正确性。";publicstaticreadonlystringDOCIN_DOWN="正在下载第{0}个资源";publicstaticreadonlystringDOCIN_DOWN_ERROR="下载第{0}个资源失败,豆丁服务器异常,请重新尝试下载。";}publicclass_WEB_DOMAIN{publicstaticreadonlystringBAIDU="BAIDU";publicstaticreadonlystringDOCIN="DOCIN";}publicenumDOC_TYPE{DOC,PDF,PPT,XLS,TXT}publicstaticvoidClear(){if(Directory.Exists("temp"))Directory.Delete("temp",true);}publicstaticvoidDecompress(stringinFile,stringoutFile){System.IO.FileStreamoutFileStream=newSystem.IO.FileStream(outFile,System.IO.FileMode.Create);ZOutputStreamoutZStream=newZOutputStream(outFileStream);System.IO.FileStreaminFileStream=newSystem.IO.FileStream(inFile,System.IO.FileMode.Open);try{byte[]buffer=newbyte[2000];intlen;while((len=inFileStream.Read(buffer,0,2000))>0){outZStream.Write(buffer,0,len);}outZStream.Flush();}finally{outZStream.Close();outFileStream.Close();inFileStream.Close();}}publicstaticvoidDecompress(StreaminStream,longlength,stringoutFile){FileStreamoutFileStream=newFileStream(outFile,FileMode.Create);ZOutputStreamoutZStream=newZOutputStream(outFileStream);try{byte[]buffer=newbyte[2000];while(length>0){if(length>=2000){inStream.Read(buffer,0,2000);outZStream.Write(buffer,0,2000);length-=2000;}else{inStream.Read(buffer,0,(int)length);outZStream.Write(buffer,0,(int)length);break;}}outZStream.Flush();}finally{outZStream.Close();outFileStream.Close();}}}}

Iwork.csusingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceDocDown{interfaceIwork{voidRun();}}

Work.csusingSystem;usingSystem.Text;usingSWFToImage;usingiTextSharp.text;usingiTextSharp.text.pdf;usingSystem.IO;namespaceDocDown{publicabstractclassWork:Iwork{protectedfrmMain_frmMain;protectedboolflag=false;protectedinttotalPage;publicWork(frmMain_frmMain){this._frmMain=_frmMain;}protectedvoidGetJPG(){_frmMain.ChangelblMsgText(Global._WORK_STATUS_INFO.CONVERT_JPG);_frmMain.ChangepbarMainState(0);SWFToImageObjectobj=newSWFToImageObject();obj.ImageWidth=Global._JPG_SIZE.W;obj.ImageHeight=Global._JPG_SIZE.H;obj.ImageOutputType=SWFToImage.TImageOutputType.iotJPG;for(inti=1;i<=totalPage;i++){obj.InputSWFFileName=string.Format(Global._FILE_PATH.SWF_FULL_PATH,AppDomain.CurrentDomain.BaseDirectory,i);obj.Execute();obj.SaveToFile(string.Format(Global._FILE_PATH.JPG_SMALL_PATH,i));_frmMain.ChangepbarMainState(100*i/totalPage);}}protectedvoidGetPDF(){_frmMain.ChangelblMsgText(Global._WORK_STATUS_INFO.CREATE_PDF);Documentdoc=newDocument(PageSize.A2,30,30,5,5);PdfWriter.GetInstance(doc,newFileStream(string.Format(Global._FILE_PATH.PDF_FULL_PATH,_frmMain._DOC_INFO.PDF_SAVE_DIR,_frmMain._DOC_INFO.DOC_NAME),FileMode.Create));doc.Open();StreamReadersr=null;for(inti=1;i<=totalPage;i++){sr=newStreamReader(string.Format(Global._FILE_PATH.JPG_SMALL_PATH,i));doc.Add(iTextSharp.text.Image.GetInstance(sr.BaseStream));sr.Close();}doc.Close();}publicabstractvoidRun();protectedvoidDownError(){DownError(0);}protectedvoidDownError(intpage){if(0==page)_frmMain.ChangelblMsgText(Global._WORK_STATUS_INFO.DOWN_ERROR);else_frmMain.ChangelblMsgText(string.Format(Global._WORK_STATUS_INFO.DOCIN_DOWN_ERROR,page));_frmMain.ChangeBtnSubmitText(true);flag=true;Global.Clear();}}}

UrlRequest.csusingSystem;usingSystem.Net;usingSystem.IO;usingSystem.Text;usingSystem.Text.RegularExpressions;namespaceDocDown{publicclassUrlRequest{publicstaticWebResponseSend(stringurl){intx=5;WebRequesthwr;ABC:try{hwr=(WebRequest)WebRequest.Create(url);hwr.Method="GET";hwr.KeepAlive=false;return(WebResponse)hwr.GetResponse();}catch{if(x!=0){x--;gotoABC;}elsereturnnull;}}publicstaticstringGetText(stringurl,Encodingenc){stringstr=string.Empty;StreamReaderreader=null;Streamstream=null;try{WebResponseresponse=Send(url);if(null==response)returnstring.Empty;stream=response.GetResponseStream();reader=newStreamReader(stream,enc);str=reader.ReadToEnd();}finally{if(null!=stream){stream.Close();reader.Close();}}returnstr;}publicstaticstringGetJson(stringvalue,stringkey){returnRegex.Replace(value,string.Format("{{.*?{0}:\"(.*?)\".*}}",key),"$1");}publicstaticstringGetJsons(stringvalue,stringkey){returnRegex.Replace(value,string.Format("{{.*?{0}:\\[(.*?)\\].*}}",key),"$1");}}}

DOC_INFO.csusingSystem;usingSystem.Text;namespaceDocDown{publicclassDOC_INFO{publicstring_DOC_INFO;publicstringDOC_ID;publicstringDOC_NAME;publicstringDOC_TYPE;publicinttotal_page;publicintCON_SUC;publicintPAGE_NUMBER;publicstringDATA_URL;publicstringDATA_REGEX;publicstringDATA_PAGE_REGEX;publicstringPDF_SAVE_DIR;publicstringDOMAIN;publicstringRN;}}

frmMain.csusingSystem;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Text.RegularExpressions;usingSystem.IO;usingSystem.Threading;namespaceDocDown{publicpartialclassfrmMain:Form{#region_DOCpublicDOC_INFO_DOC_INFO;#endregion#region其他privateThread_GetPDF=null;#endregion#regiondelegatedelegatevoidbtnSubmitCallback(boolvalue);delegatevoidpbarMainCallback(intvalue);delegatevoidlblMsgCallback(stringvalue);publicvoidChangeBtnSubmitText(boolvalue){if(this.btnSubmit.InvokeRequired)this.btnSubmit.Invoke(newbtnSubmitCallback(ChangeBtnSubmitText),newobject[]{value});else{this.btnSubmit.Enabled=value;this.btnSubmit.Text=value?"开始":"处理中。。。";}}publicvoidChangepbarMainState(intvalue){if(this.pbarMain.InvokeRequired)this.pbarMain.Invoke(newpbarMainCallback(ChangepbarMainState),newobject[]{value});elsethis.pbarMain.Value=value>100?100:value;}publicvoidChangelblMsgText(stringvalue){if(this.lblMsg.InvokeRequired)this.lblMsg.Invoke(newlblMsgCallback(ChangelblMsgText),newobject[]{value});elsethis.lblMsg.Text=value;}#endregionpublicfrmMain(){InitializeComponent();}privatevoidbtnSubmit_Click(objectsender,EventArgse){_DOC_INFO=newDOC_INFO();Iworkwork=null;#region文件地址有效性判断if(!Regex.IsMatch(txtUrl.Text.Trim(),Global._DATA_REGEXS.URL,RegexOptions.IgnoreCase)){MessageBox.Show(Global._WORK_STATUS_INFO.URL_ERROR);return;}Matchmm=Regex.Match(UrlRequest.GetText(txtUrl.Text.Trim(),Global._FILE_ENCODING.CN),Global._DATA_REGEXS.BAIDU_DOC_INFO);if(mm.Success){_DOC_INFO.DOMAIN="BAIDU";gotoFLAG;}mm=Regex.Match(UrlRequest.GetText(txtUrl.Text.Trim(),Encoding.UTF8),Global._DATA_REGEXS.DOCIN_DOC_INFO);if(mm.Success){_DOC_INFO.DOMAIN="DOCIN";gotoFLAG;}MessageBox.Show(Global._WORK_STATUS_INFO.URL_ERROR);return;#endregionFLAG:#region初始化信息//初始化界面控件lblMsg.Text=string.Empty;pbarMain.Value=0;btnSubmit.Enabled=false;fbdSaveDir.ShowDialog();btnSubmit.Text=Global._WORK_STATUS_INFO.BUSY;//初始化文件信息if(Global._WEB_DOMAIN.BAIDU==_DOC_INFO.DOMAIN){_DOC_INFO._DOC_INFO=mm.Groups[1].Value;_DOC_INFO.DOC_ID=UrlRequest.GetJson(_DOC_INFO._DOC_INFO,"doc_id");_DOC_INFO.DOC_NAME=UrlRequest.GetJson(_DOC_INFO._DOC_INFO,"doc_name");_DOC_INFO.DOC_TYPE=UrlRequest.GetJson(_DOC_INFO._DOC_INFO,"doc_type");if(Global.DOC_TYPE.TXT.ToString()==_DOC_INFO.DOC_TYPE.ToUpper()){_DOC_INFO.RN="50";_DOC_INFO.DATA_URL=Global._DATA_URL_FROMAT.BAIDU_DATA_URL_TXT;_DOC_INFO.DATA_REGEX=Global._DATA_REGEXS.BAIDU_DATA_HEADER;}else{_DOC_INFO.DATA_URL=Global._DATA_URL_FROMAT.BAIDU_DATA_URL_NOT_TXT;_DOC_INFO.DATA_REGEX=Global._DATA_REGEXS.BAIDU_DATA;_DOC_INFO.DATA_PAGE_REGEX=Global._DATA_REGEXS.BAIDU_DATA_SWF;_DOC_INFO.RN="5";}work=newBAIDU(this);}else{_DOC_INFO._DOC_INFO=mm.Groups[1].Value;_DOC_INFO.DOC_ID=Regex.Replace(txtUrl.Text.Trim().ToLower(),@"://www\.docin\/p-(\d+?)\.html","$1");//_DOC_INFO.DATA_URL=Global._DATA_URL_FROMA;_DOC_INFO.PAGE_NUMBER=int.Parse(UrlRequest.GetJsons(_DOC_INFO._DOC_INFO,"\"pageNum\""));_DOC_INFO.DOC_NAME=UrlRequest.GetJsons(_DOC_INFO._DOC_INFO,"\"pdtTitle\"").Trim('"');_DOC_INFO.DOC_TYPE=UrlRequest.GetJsons(_DOC_INFO._DOC_INFO,"\"pdtType\"").Trim('"');_DOC_INFO.CON_SUC=int.Parse(UrlRequest.GetJsons(_DOC_INFO._DOC_INFO,"\"converSuccess\""));work=newDOCIN(this);}//其他_DOC_INFO.PDF_SAVE_DIR=fbdSaveDir.SelectedPath;//初始化临时文件目录if(!Directory.Exists(Global._FILE_PATH.TEMP_SMALL_PATH))Directory.CreateDirectory(Global._FILE_PATH.TEMP_SMALL_PATH);#endregion#region启动线程_GetPDF=newThread(newThreadStart(work.Run));_GetPDF.IsBackground=true;_GetPDF.Start();#endregion}privatevoidfrmMain_FormClosing(objectsender,FormClosingEventArgse){Global.Clear();}}}

BAIDU.csusingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Text.RegularExpressions;usingSWFToImage;usingiTextSharp.text;usingiTextSharp.text.pdf;usingSystem.IO;namespaceDocDown{publicclassBAIDU:Work{publicBAIDU(frmMain_frmMain):base(_frmMain){}publicoverridevoidRun(){if(_frmMain._DOC_INFO.DOC_TYPE.ToUpper()==Global.DOC_TYPE.TXT.ToString()){GetTXT(1);}else{GetSWF(1);if(flag)return;GetJPG();GetPDF();}Global.Clear();_frmMain.ChangelblMsgText(Global._WORK_STATUS_INFO.SUCCESS);_frmMain.ChangeBtnSubmitText(true);}privatevoidGetSWF(intfromPage){if(fromPage==1)_frmMain.ChangelblMsgText(Global._WORK_STATUS_INFO.START_WORK);inttoPage=0;stringvalue=UrlRequest.GetText(string.Format(_frmMain._DOC_INFO.DATA_URL,_frmMain._DOC_INFO.DOC_ID,fromPage,_frmMain._DOC_INFO.RN),Global._FILE_ENCODING.EN);if(string.IsNullOrEmpty(value)){DownError();return;}Matchmatch=Regex.Match(value,_frmMain._DOC_INFO.DATA_REGEX);if(match.Success){stringswf_info=match.Groups[1].Value;toPage=int.Parse(UrlRequest.GetJson(swf_info,"\"toPage\""));if(1==fromPage)totalPage=int.Parse(UrlRequest.GetJson(swf_info,"\"totalPage\""));}else{DownError();return;}MatchCollectionMC=Regex.Matches(value,_frmMain._DOC_INFO.DATA_PAGE_REGEX);for(inti=fromPage,j=0;i<=toPage;i++,j++){System.IO.File.WriteAllText(string.Format(Global._FILE_PATH.SWF_SMALL_PATH,i),MC[j].Value,Global._FILE_ENCODING.EN);_frmMain.ChangepbarMainState(100*i/totalPage);}if(toPage<totalPage)GetSWF(toPage+1);}privatevoidGetTXT(intfromPage){if(fromPage==1)_frmMain.ChangelblMsgText(Global._WORK_STATUS_INFO.START_WORK);inttoPage=0;stringvalue=UrlRequest.GetText(string.Format(_frmMain._DOC_INFO.DATA_URL,_frmMain._DOC_INFO.DOC_ID,fromPage,_frmMain._DOC_INFO.RN),Global._FILE_ENCODING.EN);if(string.IsNullOrEmpty(value)){DownError();return;}Matchmatch=Regex.Match(value,_frmMain._DOC_INFO.DATA_REGEX);if(match.Success){stringswf_info=match.Groups[1].Value;toPage=int.Parse(UrlRequest.GetJson(swf_info,"\"toPage\""));if(1==fromPage)totalPage=int.Parse(UrlRequest.GetJson(swf_info,"\"totalPage\""));}else{DownError();return;}System.IO.File.AppendAllText(string.Format(Global._FILE_PATH.TXT_FULL_PATH,_frmMain._DOC_INFO.PDF_SAVE_DIR,_frmMain._DOC_INFO.DOC_NAME),match.Groups[2].Value,Global._FILE_ENCODING.EN);_frmMain.ChangepbarMainState(100*toPage/totalPage);if(toPage<totalPage)GetTXT(toPage+1);}}}

namespaceDocDown{partialclassfrmMain{///<summary>///Requireddesignervariable.///</summary>privateSystemponentModel.IContainercomponents=null;///<summary>///Cleanupanyresourcesbeingused.///</summary>///<paramname="disposing">trueifmanagedresourcesshouldbedisposed;otherwise,false.</param>protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindowsFormDesignergeneratedcode///<summary>///RequiredmethodforDesignersupport-donotmodify///thecontentsofthismethodwiththecodeeditor.///</summary>privatevoidInitializeComponent(){this.gboxUrl=newSystem.Windows.Forms.GroupBox();this.txtUrl=newSystem.Windows.Forms.TextBox();this.btnSubmit=newSystem.Windows.Forms.Button();this.pbarMain=newSystem.Windows.Forms.ProgressBar();this.lblMsg=newSystem.Windows.Forms.Label();this.fbdSaveDir=newSystem.Windows.Forms.FolderBrowserDialog();this.gboxUrl.SuspendLayout();this.SuspendLayout();////gboxUrl//this.gboxUrl.Controls.Add(this.txtUrl);this.gboxUrl.Location=newSystem.Drawing.Point(1,5);this.gboxUrl.Name="gboxUrl";this.gboxUrl.Padding=newSystem.Windows.Forms.Padding(4,3,4,3);this.gboxUrl.Size=newSystem.Drawing.Size(400,47);this.gboxUrl.TabIndex=2;this.gboxUrl.TabStop=false;this.gboxUrl.Text="文库地址";////txtUrl//this.txtUrl.Dock=System.Windows.Forms.DockStyle.Top;this.txtUrl.Location=newSystem.Drawing.Point(4,17);this.txt

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论