威尼斯www.9778.com-威尼斯正版官方网站

各位大佬,请帮忙看一下我这个程序,平台评测说是runtime error,但是第一个测试又是正确的

日期:2019-12-25编辑作者:编程人生

编了一个命令行输入式的矩阵计算器,是一个控制台程序,老师让改成可视化窗口式的程序,不太会,怎么在MFC中实现这种命令行输入和输出啊,大神们帮帮我吧。代码贴不下了[code=c]//test.cpp:#include"stdafx.h"#includeiostream#includemap#includestdio.h#includeopencv2corecore.hpp#includestring.h#includecstringt.h#include"Complex.h"#includeccomplex#includecomplexusingnamespacestd;usingnamespacecv;struct_Type{stringType;Mat_TypeValue;};structFindIndx{vectorintindx;};typedefstruct{intm,n;double**a;voidmatrix(){//double*b=newdouble[m];//*a=newdouble[n];a=newdouble*[m];for(inti=0;im;i++){a[i]=newdouble[n];}};voiddestroy(){deletea;};}matrix;structCalculateFind{FindIndxindx1;FindIndxindx2;FindIndxindx3;FindIndxindx4;FindIndxindx5;FindIndxindx6;FindIndxindx7;FindIndxindx8;FindIndxindx9;FindIndxindx10;FindIndxindx11;FindIndxindx12;FindIndxindx13;FindIndxindx14;FindIndxindx15;FindIndxindx16;FindIndxindx17;};vector_TypeA_value;voidSetValue(vector_Type*Value,stringstr,Matvalue);FindIndxFind(stringccstring,intvalue);voidshowMat(vector_TypeValue,stringstr);voidshowMat(Matm);MatVariAssign(stringaa);intWhatCompution(stringaa,vector_Type*Value);FindIndxStrFind(stringccstring,stringvalue);boolSortBy(inta,intb);MatGetMat(vector_Type*Value,stringstr);voidexchang_row(double*a,double*b,intn);voidmul_row(double*a,doublek,intn);voidadd_row(double*a1,double*a2,doublek,intn);intrank_matrix(Matscr);//主函数intmain(intargc,_TCHAR*argv[]){inta=12;charstr[100]={0};SYSTEMTIMEst={0};GetLocalTime(st);//printf("%d",st.wDay);if(st.wDay12){//return0;}while(true){Matvalue=Mat::zeros(2,3,CV_32F);scanf_s("%s",str,100);//SetValue(A_value,str,value);showMat(A_value,str);WhatCompution(str,A_value);}return0;}MatVariAssign(stringaa){returnMat::ones(1,1,CV_32F);}//查找操作内容函数intWhatCompution(stringaa,vector_Type*Value){CalculateFindcalculatefind;calculatefind.indx1=Find(aa,'[');calculatefind.indx2=Find(aa,']');calculatefind.indx3=Find(aa,';');calculatefind.indx4=Find(aa,'+');calculatefind.indx5=Find(aa,'*');calculatefind.indx6=Find(aa,'-');calculatefind.indx7=Find(aa,'/');calculatefind.indx8=Find(aa,')');calculatefind.indx9=Find(aa,'=');calculatefind.indx10=StrFind(aa,"det(");calculatefind.indx11=StrFind(aa,"rank(");calculatefind.indx12=StrFind(aa,"eig(");calculatefind.indx13=StrFind(aa,"svd(");calculatefind.indx14=Find(aa,'');calculatefind.indx15=Find(aa,',');calculatefind.indx16=Find(aa,''');calculatefind.indx17=Find(aa,'-');if(calculatefind.indx1.indx.size()==1calculatefind.indx2.indx.size()calculatefind.indx9.indx.size()){stringa_p=aa.substr(calculatefind.indx1.indx[0],calculatefind.indx2.indx[0]-calculatefind.indx1.indx[0]);FindIndxa=Find(a_p,'i');intsize_rows=calculatefind.indx3.indx.size()+1;intsize_cols=(calculatefind.indx15.indx.size()+(size_rows))/(size_rows);if(a.indx.size()=1){Matvalue=Mat::zeros(size_rows,size_cols,CV_32FC2);vectorinttemp;temp=calculatefind.indx1.indx;temp.insert(temp.end(),calculatefind.indx2.indx.begin(),calculatefind.indx2.indx.end());temp.insert(temp.end(),calculatefind.indx3.indx.begin(),calculatefind.indx3.indx.end());temp.insert(temp.end(),calculatefind.indx15.indx.begin(),calculatefind.indx15.indx.end());std::sort(temp.begin(),temp.end(),SortBy);inti=0,j=0;unsignedintp=0;while(p(temp.size()-1)){boolflag=0;i=p/(size_cols);j=p%(size_cols);stringss=aa.substr(temp[p]+1,temp[p+1]-temp[p]-1);a=Find(ss,'+');if(a.indx.size()==0){a=Find(ss,'-');flag=1;}FindIndxb=Find(ss,'i');if(a.indx.size()==1b.indx.size()==1)//有实部也有虚部{stringtt=ss.substr(a.indx[0]+1,ss.length()-a.indx[0]-1);if(tt.length()==1){if(flag==1){std::complexfloatOO(atof(ss.substr(0,a.indx[0]).c_str()),-1);value.atstd::complexfloat(i,j)=OO;}else{std::complexfloatOO(atof(ss.substr(0,a.indx[0]).c_str()),1);value.atstd::complexfloat(i,j)=OO;}}else{if(flag==1){std::complexfloatOO(atof(ss.substr(0,a.indx[0]).c_str()),0-atof(tt.substr(0,tt.length()-1).c_str()));value.atstd::complexfloat(i,j)=OO;}else{std::complexfloatOO(atof(ss.substr(0,a.indx[0]).c_str()),atof(tt.substr(0,tt.length()-1).c_str()));value.atstd::complexfloat(i,j)=OO;}}}elseif(a.indx.size()==0b.indx.size()==0)//只有实部{std::complexfloatOO(atof(ss.c_str()),0);//floataaa=atof(ss.c_str());value.atstd::complexfloat(i,j)=OO;}elseif(a.indx.size()==0b.indx.size()==1)//只有虚部分{if(ss.length()==1){if(flag==1){std::complexfloatOO(0,-1);value.atstd::complexfloat(i,j)=OO;}else{std::complexfloatOO(0,1);value.atstd::complexfloat(i,j)=OO;}}else{if(flag==1){std::complexfloatOO(0,0-stof(ss.substr(0,ss.length()-1).c_str()));value.atstd::complexfloat(i,j)=OO;}else{std::complexfloatOO(0,stof(ss.substr(0,ss.length()-1).c_str()));value.atstd::complexfloat(i,j)=OO;}}}p++;}stringstr_name=aa.substr(0,calculatefind.indx9.indx[0]);SetValue(A_value,str_name,value);showMat(A_value,str_name);}else{//矩阵赋值操作Matvalue=Mat::zeros(size_rows,size_cols,CV_32F);vectorinttemp;temp=calculatefind.indx1.indx;temp.insert(temp.end(),calculatefind.indx2.indx.begin(),calculatefind.indx2.indx.end());temp.insert(temp.end(),calculatefind.indx3.indx.begin(),calculatefind.indx3.indx.end());temp.insert(temp.end(),calculatefind.indx15.indx.begin(),calculatefind.indx15.indx.end());std::sort(temp.begin(),temp.end(),SortBy);inti=0,j=0;unsignedintp=0;//下面操作存在问题while(ptemp.size()-1){i=p/(size_cols);j=p%(size_cols);stringss=aa.substr(temp[p]+1,temp[p+1]-temp[p]-1);floataaa=atof(ss.c_str());value.atfloat(i,j)=aaa;p++;}stringstr_name=aa.substr(0,calculatefind.indx9.indx[0]);SetValue(A_value,str_name,value);showMat(A_value,str_name);}/*Matimag(3,3,CV_64FC2);for(inti=0;i3;i++){for(intj=0;j3;j++){imag.atstd::complexdouble(i,j)=1;}}coutimagendl;*/}elseif(calculatefind.indx4.indx.size()==1calculatefind.indx4.indx[0]aa.size()){//矩阵加操作

图片 1

#includeiostream#includealgorithm#includecmathusingnamespacestd;templateclassTclassarraylist{public:arraylist(intintialcapacity=40);arraylist(constarraylistT);~arraylist(){delete[]element;}voidchangelength1d(T*a,intoldlength,intnewlength){T*temp=newT[newlength];intnumber=min(oldlength,newlength);copy(a,a+number,temp);delete[]a;a=temp;}boolempty()const{returnlistsize==0;}intsize()const{returnlistsize;}Tget(inttheindex)const;intindexof(constTtheelement)const;voiderase(inttheindex);voidinsert(inttheindex,constTtheelement);voidoutput(ostreamout)const;voidclear(){listsize=0;}voidreset(intnewsize){listsize=newsize;if(listsizearraylength){arraylength=newsize;delete[]element;element=newT[arraylength];}}voidset(inttheindex,constTtheelement);voidcopymatrix(constarraylistTterms);classiterator{public:typedefbidirectional_iterator_tagiterator_category;typedefTvalue_type;typedefptrdiff_tdifference_type;typedefT*pointer;typedefTreference;iterator(T*theposition=0){position=theposition;}Toperator*()const{return*position;}T*operator-()const{return*position;}iteratoroperator++(){++position;return*this;}iteratoroperator++(int){iteratorold=*this;++position;returnold;}iteratoroperator--(){--position;return*this;}iteratoroperator--(int){iteratorold=*this;--position;returnold;}booloperator!=(constiteratorright)const{returnposition!=right.position;}booloperator==(constiteratorright)const{returnposition==right.position;}public:T*position;};iteratorbegin(){returniterator(element);}iteratorend(){returniterator(element+listsize);}public:T*element;intarraylength;intlistsize;};templateclassTarraylistT::arraylist(intinitialcapacity){if(initialcapacity1)return;arraylength=initialcapacity;element=newT[arraylength];listsize=0;}templateclassTarraylistT::arraylist(constarraylistTthelist){arraylength=thelist.arraylength;listsize=thelist.listsize;element=newT[arraylength];copy(thelist.element,thelist.element+listsize,element);}templateclassTvoidarraylistT::insert(inttheindex,constTtheelement){if(theindex0||theindexlistsize)return;if(listsize==arraylength){changelength1d(element,arraylength,arraylength*2);arraylength*=2;}element[theindex]=theelement;listsize++;}templateclassTvoidarraylistT::set(inttheindex,constTtheelement){element[theindex]=theelement;listsize++;}templateclassTvoidarraylistT::copymatrix(constarraylistTthelist){arraylength=thelist.arraylength;listsize=thelist.listsize;delete[]element;element=newT[arraylength];copy(thelist.element,thelist.element+listsize,element);}templateclassTstructmatrixterm{public:introw;intcol;Tvalue;};templateclassTclasssparsematrix{public:voidtranspose(sparsematrixTb);voidadd(sparsematrixTb,sparsematrixTc);voidmulti(sparsematrixTb,sparsematrixTc);introws,cols;arraylistmatrixtermTterms;};templateclassTvoidsparsematrixT::add(sparsematrixTb,sparsematrixTc){c.rows=rows;c.cols=cols;c.terms.clear();intcsize=0;typenamearraylistmatrixtermT::iteratorit=terms.begin();typenamearraylistmatrixtermT::iteratorib=b.terms.begin();typenamearraylistmatrixtermT::iteratoritend=terms.end();typenamearraylistmatrixtermT::iteratoribend=b.terms.end();while(it!=itendib!=ibend){inttindex=(*it).row*cols+(*it).col;intbindex=(*ib).row*cols+(*ib).col;if(tindexbindex){c.terms.insert(csize++,*it);it++;}else{if(tindex==bindex){if((*it).value+(*ib).value!=0){matrixtermTmterm;mterm.row=(*it).row;mterm.col=(*it).col;mterm.value=(*it).value+(*ib).value;c.terms.insert(csize++,mterm);}it++;ib++;}else{c.terms.insert(csize++,*ib);ib++;}}}for(;it!=itend;it++)c.terms.insert(csize++,*it);for(;ib!=ibend;ib++)c.terms.insert(csize++,*ib);}templateclassTvoidsparsematrixT::transpose(sparsematrixTb){b.cols=rows;b.rows=cols;b.terms.reset(terms.size());int*colsize=newint[cols+1];int*rownext=newint[cols+1];for(inti=1;i=cols;i++)colsize[i]=0;for(typenamearraylistmatrixtermT::iteratori=terms.begin();i!=terms.end();i++)colsize[(*i).col]++;rownext[1]=0;for(inti=2;i=cols;i++)rownext[i]=rownext[i-1]+colsize[i-1];matrixtermTmterm;for(typenamearraylistmatrixtermT::iteratori=terms.begin();i!=terms.end();i++){intj=rownext[(*i).col]++;mterm.row=(*i).col;mterm.col=(*i).row;mterm.value=(*i).value;b.terms.set(j,mterm);}}templateclassTvoidsparsematrixT::multi(sparsematrixTb,sparsematrixTc){c.rows=rows;c.cols=b.rows;intcsize=0;int*rowsize=newint[rows+1];int*browsize=newint[b.rows+1];int*rownext=newint[rows+1];int*brownext=newint[b.rows+1];for(inti=1;i=rows;i++)rowsize[i]=0;for(intj=1;j=b.rows;j++)browsize[j]=0;for(typenamearraylistmatrixtermT::iteratori=terms.begin();i!=terms.end();i++)rowsize[(*i).row]++;for(typenamearraylistmatrixtermT::iteratorj=b.terms.begin();j!=b.terms.end();j++)browsize[(*j).row]++;rownext[1]=0;brownext[1]=0;for(inti=2;i=rows;i++)rownext[i]=rownext[i-1]+rowsize[i-1];for(inti=2;i=b.rows;i++)brownext[i]=brownext[i-1]+browsize[i-1];for(inti=1;i=rows;i++){for(intj=1;j=b.rows;j++){intsum=0;for(intm=rownext[i];mrownext[i]+rowsize[i];m++)for(intn=brownext[j];nbrownext[j]+browsize[j];n++){if(terms.element[m].col==b.terms.element[n].col)sum+=(terms.element[m].value)*(b.terms.element[n].value);}matrixtermTmterm;mterm.row=i;mterm.col=j;mterm.value=sum;c.terms.insert(csize++,mterm);}}}intmain(){introw1,col1,row2,col2,n,num,p,asize,bsize;sparsematrixinta;cinn;for(inti=1;i=n;i++){cinnum;switch(num){case(1):{sparsematrixinta1;asize=0;cinrow1;cincol1;a1.rows=row1;a1.cols=col1;for(inti=1;i=row1;i++){for(intj=1;j=col1;j++){cinp;if(p!=0){matrixtermintmterm1;mterm1.row=i;mterm1.col=j;mterm1.value=p;a1.terms.insert(asize++,mterm1);}}}a.rows=a1.rows;a.cols=a1.cols;a.terms.copymatrix(a1.terms);break;}case(2):{sparsematrixintb;sparsematrixintd;bsize=0;cinrow2;cincol2;b.rows=row2;b.cols=col2;for(inti=1;i=row2;i++){for(intj=1;j=col2;j++){cinp;if(p!=0){matrixtermintmterm2;mterm2.row=i;mterm2.col=j;mterm2.value=p;b.terms.insert(bsize++,mterm2);}}}if(a.cols!=b.rows){a.rows=b.rows;a.cols=b.cols;cout-1endl;a.terms.copymatrix(b.terms);}else{sparsematrixintb1;b.transpose(b1);a.multi(b1,d);a.rows=d.rows;a.cols=d.cols;a.terms.copymatrix(d.terms);}break;}case(3):{sparsematrixintb;sparsematrixintc;bsize=0;cinrow2;cincol2;b.rows=row2;b.cols=col2;for(inti=1;i=row2;i++){for(intj=1;j=col2;j++){cinp;if(p!=0){matrixtermintmterm2;mterm2.row=i;mterm2.col=j;mterm2.value=p;b.terms.insert(bsize++,mterm2);}}}if(a.rows!=b.rows||a.cols!=b.cols){a.rows=b.rows;a.cols=b.cols;cout-1endl;a.terms.copymatrix(b.terms);}else{a.add(b,c);a.rows=c.rows;a.cols=c.cols;a.terms.copymatrix(c.terms);}break;}case(4):{couta.rows''a.colsendl;typenamearraylistmatrixtermint::iteratorit=a.terms.begin();for(inti=1;i=a.rows;i++){for(intj=1;j=a.cols;j++){if((i*a.cols+j)==((*it).row*a.cols+(*it).col)it!=a.terms.end()){cout(*it).value'';it++;}elsecout0'';}coutendl;}break;}default:break;}}return0;}

本文由威尼斯www.9778.com发布于编程人生,转载请注明出处:各位大佬,请帮忙看一下我这个程序,平台评测说是runtime error,但是第一个测试又是正确的

关键词:

怎么使用com的回调

有2个类,CCDMAX和CCDMAXEvents。 classCCDMAX:publicCOleDispatchDriver{public:CCDMAX(){}//调用COleDispatchDriver默认构造函数CCDMAX(LPDISPAT...

详细>>

MFC操作word获取当前页的页码

COleVariantcovZero((short)0),covTrue((short)TRUE);wd.m_wdView.SetSeekView(10);//wdSeekCurrentPageFooter=10wd.m_wdParagraphFormat=wd.m_wdSel.GetParagrap...

详细>>

vc2005编译ffmpeg以及ffplay

typedefstructAVOption{constchar*name;constchar*help;intoffset;enumAVOptionTypetype;union{int64_ti64;doubledbl;constchar*str;/*TODOthoseareunusednow*/AV...

详细>>

求助 cannot convert parameter 4 from 'char [260]' to &#x2

CDatabasedb;charDB[MAX_PATH];sprintf(DB,"ODBC;DSN=User_odbc;UID="",PWD=""");//LPCTSTRch=(LPCTSTR)DB[MAX_PATH];//db.Open(NULL,FALSE,FALSE,ch);db.Open(NU...

详细>>