Nine degrees [1080] binary conversion

Source: Internet
Author: User

1# include<iostream>2# include<string>3# include<cstring>4 using namespacestd;5 structbigint{//Define a large integer class6     inta[ -];7     intremain;8     inti;9BigInt &operator*(int& value) {//overloaded multiplicationTen          for(i=0;i< -; i++) Onea[i]=a[i]*value; A         intC=0; -          for(i=0;i< -; i++){ -a[i]=a[i]+C; thec=a[i]/ -; -a[i]=a[i]% -; -         } -         return* This; +     } -     BOOL operator!=(Const int& value)//determines whether an integer is 0 +     { A          for(i=0;i< -; i++) at             if(A[i]!=value) Break; -         if(i< -)return true; -         return false; -     } -BigInt &operator/(int&value) {//Overloaded Division -         intC=0; in          for(i=499; i>=0; i--) -             if(a[i]!=0) Break; to         //cout<< "I" <<i<<endl; +          for(; i>=0; i--) -         { theA[i]= (a[i]+c* -); *c=a[i]%value; $a[i]=a[i]/value;Panax Notoginseng         } -remain=C; the         return* This; +     } A }; the intMain () { +     intm=0, n=0; -     intI=0; $      while(cin>>m>>N) { $         strings; -Cin>>s; -         if(s=="0") {cout<<0<<endl;Continue;} the         intL=s.size (); - bigint Bida;Wuyimemset (BIDA.A,0,sizeof(BIDA.A)); the          for(i=0; i<l;i++) -         { Wu             intk=m; -             if(i!=0) bida=bida*K; About             if(s[i]<='9') { $                 intk=s[i]-'0'; -bida.a[0]=bida.a[0]+K; -             } -             Else { A                 intk=s[i]-'A'+Ten; +bida.a[0]=bida.a[0]+K; the             } -}//Convert to decimal number Bida; $         //cout<<bida.a[0]; the         intb[ -]; theI=0; thememset (b,0,sizeof(b)); the          while(bida!=0){ -bida=bida/N; inb[i]=Bida.remain; thei++; the         } About          for(i=i-1; i>=0; i--) the         { the             if(b[i]>9) {Charc=b[i]-Ten+'a';cout<<C;} the             Elsecout<<B[i]; +         } -cout<<Endl; the     }Bayi     return 0; the}

It's a little messy, first pass. Go back and finish.

Nine degrees [1080] binary conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.