Portal: http: //ybt.ssoier.cn: 8088 / problem_show.php pid = 1308?
Description [title]
High-precision divided by the high refinement, and their quotient and remainder.
[Enter]
Two input 300 is less than the positive integer.
[Output]
Output quotient and remainder.
[Sample input]
1231312318457577687897987642324567864324567876543245671425346756786867867867 1231312318767141738178325678412414124141425346756786867867867
[Sample Output]
999999999748590 179780909068307566598992807564736854549985603543237528310337
dividend if it is 9, the divisor is 6, then adding the two high-precision subtraction divisor, each time adding provider 100 (the number of 0 bits of the dividend divisor is subtracted median -1) to.
Examples:
9745/3
the first time | 9745 | 300 | Save 32, I 145 | Business 32 * 100 |
the second time | 145 | 30 | Minus 4 times, more than 25 | List 32 * 100 * 10 + 4 |
the third time | 25 | 3 | Minus eight times, more than 1 | List 32 * 100 + 4 * 10 + 8 * 1 |
code:
#include<iostream> #include<cstring> #define N 310 using namespace std; string a,b; int as[310],bs[310],ans[310],lena,lenb; void jian(){ for(int i=0;i<lena;i++)as[i]-=bs[i]; for(int i=0;i<lena;i++) { if(as[i]<0){ as[i]+=10; as[i+1]--; } } while(as[lena-1]==0&&lena>0)lena--; } bool dx(){ if(lena>lenb)return true; if(lena<lenb)return false; for(int i=lena-1;i>=0;i--){ if(as[i]>bs[i])return true; if(as[i]<bs[i])return false; } return true; } void you ( int k) { if(k==0)k=1; if(k!=1) { for(int i=lenb-1;i>=0;i--) { bs [i + k- 1 ] = bs [i]; bs [i] = 0 ; } lenb+=k-1; } while(dx()==true){ jian (); ans[k-1]++; int ls=k-1; for(int i=k-1;i<=ls;i++) { if(ans[i]>9){ years [i + 1 ] ++ ; ans[i]-=10; if(ans[i+1]>9)ls++; } } } if(k!=1) { for(int i=k-1;i<lenb;i++) { bs [in -k + 1 ] = bs [i]; bs [i] = 0 ; } lenb-=k-1; } } int main () { cin>>a>>b; if(a==b){cout<<1<<endl<<0<<endl;return 0;} lena=a.size(); lenb=b.size(); for(int i=0;i<lena;i++)as[i]=a[lena-i-1]-'0'; for(int i=0;i<lenb;i++)bs[i]=b[lenb-i-1]-'0'; memset(ans,0,sizeof(ans)); int k=lena-lenb; if(k<0){cout<<0<<endl<<a<<endl;return 0;} while(k>=0){ if(k==0&&dx()==false)break; you (k); k=lena-lenb; } int h1=301,h2=301; while(ans[h1]==0&&h1>0)h1--; while(as[h2]==0&&h2>0)h2--; for(int i=h1;i>=0;i--)cout<<ans[i]; cout<<endl; for(int i=h2;i>=0;i--)cout<<as[i]; cout<<endl; }
The first to write blog
This problem did not watch gangster
Better approach really can not think of