用C++写的两个任意位数的数相加
c++吧
全部回复
仅看楼主
level 1
AM菜鸟 楼主
#include
#include
#include
using namespace std;class Box{public: Box(int a){num=a;} int getnum(){return num;}private:int num;};class Passage { public: Passage(Box* cbox){abox=cbox;pnext=NULL;ptou=NULL;} void setnext1(Passage* ppassage){pnext=ppassage;} void setnext2(Passage* pppassage){ptou=pppassage;} Passage* getnext(){return pnext;} Passage* gettou(){return ptou;} Box* getabox(){return abox;} private: Box* abox; Passage* pnext; Passage* ptou;};class Tuke{public:Tuke(){phead=pcurrent=pend=NULL;}void add(Box* pbox);Box* getfirstbox();Box* getendbox(); Box* getmillbox();void movebox();int judge();private:Passage* phead;Passage* pcurrent;Passage* pend;};void Tuke::add(Box* pbox){ Passage *passage=new Passage(pbox); if(pend!=NULL){ pend->setnext1(passage); pend=passage; pend->setnext2(pcurrent); } else {phead=passage;pend=passage;}pcurrent=pend;}Box* Tuke::getfirstbox(){return phead->getabox();} Box* Tuke::getmillbox(){ return pcurrent->getabox();}void Tuke::movebox(){pcurrent=pcurrent->gettou();}Box* Tuke::getendbox(){return pcurrent->getabox();}int Tuke::judge(){ int bol=phead==pcurrent?1:0;return bol;} int jia1(int a[],int m) { int sum=0; switch(m) { case 4: sum=a[0]*1e3+a[1]*1e2+a[2]*1e1+a[3];break; case 3: sum=a[0]*1e2+a[1]*1e1+a[2];break; case 2: sum=a[0]*1e1+a[1];break; case 1: sum=a[0];break; } return sum; } int jia2(int a[]) {int sum=0; sum=a[0]*1e3+a[1]*1e2+a[2]*1e1+a[3]; return sum; } int s,ss; void main(){ string count,count2; cin>>count>>count2; cout<<"the two number your insert is:"<<"\n"<
=count2.length()) { first=count.substr(1); second=count2.substr(1);} else {first=count2.substr(1); second=count.substr(1); } }if(count[0]!='-'&&count2[0]!='-'){ s=0; ss=0; if(count.length()>=count2.length()) { first=count; second=count2;} else {first=count2; second=count; } }if(count[0]=='-'&&count2[0]!='-'){ ss=1; third=count.substr(1); int jf; if(third.length()>count2.length()) {first=third; second=count2; s=1; } if(third.length()
count2[hj]?1:0; break; } } if(jf==1)
2007年10月23日 07点10分 1
level 1
AM菜鸟 楼主
{first=third; second=count2; s=1;} else {first=count2; second=third; s=0;} }} if(count[0]!='-'&&count2[0]=='-') { ss=1; forth=count2.substr(1); int js; if(count.length()>forth.length()) {first=count; second=forth; s=0; } if(count.length()
count2[hs]?1:0; break;} } if(js==1) {first=forth; second=count; s=1;} else {first=count; second=forth; s=0;} }}Tuke load1; int b[20]; for(int k=0;;k++) { if(first[k]==','||first[k]==NULL) { for(int i=0;i
4) { int r=0; string remain=first.substr(k+1); for(;r
4&&ss==0)||(second.length()>5&&ss==1)) { int b[9]; int r=0; string remain=second.substr(k2+1); for(;r
getnum()+h2box->getnum(); if(w>=10000||w<0) { if(w>=10000)ll++; else ll--; } w=ll; if(ll>=10000||ll<0){ if(ll>10000)xin[c]=ll-10000; if(ll==10000)xin[c]=0; if(ll<0&&first.length()/5+1<2)xin[c]=ll; if(ll<0&&first.length()/5+1>=2)xin[c]=ll+10000;} else xin[c]=ll;if(load1.judge()&&ll>=10000){++c; xin[c]=1;} load1.movebox(); load2.movebox(); } int last[30]={0};int hnum=4;int ct,kg=0; if(xin[c-1]==0) ct=c-2; else ct=c-1; for(;ct>=0;ct--) { int l=0; for(;;) { if(xin[ct]/1000){l=4;break;} if(xin[ct]/100){l=3;break;} if(xin[ct]/10!=0){l=2;break;} else {l=1;break;}} if(ct==c-1) {hnum=l;} switch(l) { case 4: { last[kg]=xin[ct]/1000; last[kg+1]=xin[ct]%1000/100; last[kg+2]=xin[ct]%1000%100/10; last[kg+3]=xin[ct]%1000%100%10;};break; case 3: { last[kg+1]=xin[ct]/100; last[kg+2]=xin[ct]%100/10; last[kg+3]=xin[ct]%100%10; };break; case 2: { last[kg+2]=xin[ct]/10;last[kg+3]=xin[ct]%10;};break; case 1: { last[kg+3]=xin[ct];};break; } kg=kg+4; } int jj=kg; int ji=0; printf("the result is:\n"); if(first==second&&ss==1) printf("%d",ji); else { if(s==1) printf("-");for(int fh=4-hnum;fh<4;fh++){ printf("%d",last[fh]);} printf(","); for(int f=4;f
2007年10月23日 07点10分 2
level 12
不懂
2014年02月27日 04点02分 4
level 12
用 Gist dot GitHub dot com 吧
2014年02月27日 04点02分 5
1