【高精度算法】A/B 高精度初以高精度保留余数
来源:互联网 发布:软件行业编程工具 编辑:程序博客网 时间:2024/06/05 20:06
下面程序有一点问题,但思路总是对的,请读者自己改改吧~~~~~~
#include<iostream>#include<cstring>using namespace std;const int size=101;int a[size],b[size],c[size],d,i; void init(int a[]){ string s; cin>>s;a[0]=s.length();for(i=1;i<=a[0];i++) a[i]=s[a[0]-i]-'0';}void print(int a[]){if(a[0]==0){ cout<<0<<endl;return;}for(int i=a[0];i>0;i--) cout<<a[i];cout<<endl;return ;}int compare (int a[],int b[]){ int i;if(a[0]>b[0]) return 1;if(a[0]<b[0]) return -1;for(i=a[0];i>0;i--){if (a[i]>b[i]) return 1; if (a[i]<b[i]) return -1;} return 0;} void numcpy(int p[],int q[],int det){for(int i=1;i<=p[0];i++) q[i+det-1]=p[i];q[0]=p[0]+det-1;}void jian(int a[],int b[]){int flag,i;flag=compare(a,b);if(flag==0){ a[0]=0;return;}if(flag==1){for(i=1;i<=a[0];i++){if(a[i]<b[i]){ a[i+1]--;a[i]+=10;}a[i]-=b[i];} while(a[0]>0&&a[a[0]]==0) a[0]--;return;} } void chugao(int a[],int b[],int c[]){int tmp[101]; c[0]=a[0]-b[0]+1;for(int i=c[0];i>0;i--){memset(tmp,0,sizeof(tmp));numcpy(b,tmp,i);while(compare(a,tmp)>=0) c[i]++;jian(a,tmp);}while(c[0]>0&&c[c[0]]==0)c[0]--;return ;} int main(){ memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); init(a);init(b); chugao(a,b,c); print(c); print(a); return 0;}
0 0
- 【高精度算法】A/B 高精度初以高精度保留余数
- 【高精度算法】A/B 高精度除以低精度 保留小数
- 【高精度算法】A*B
- 【高精度算法】A+B
- 【高精度算法】A+B
- 1381 a*b 高精度
- 高精度大数A+B
- A+B Problem 高精度
- A + B高精度
- a+b(高精度)
- 高精度 A*B Problem
- 高精度 A+B Problem
- 高精度 A-B Problem
- a+b高精度
- A+B高精度问题
- a+b 高精度
- 高精度求A+B
- 【高精度算法】A*B 加强版
- Python抓取网页链接
- python 抓去指定网页以及该网页上所有链接
- 链表压缩问题
- 1123549878
- startActivity()和onActivityResult() 返回上一个Activity并传值
- 【高精度算法】A/B 高精度初以高精度保留余数
- 小紫书 4-2 UVA 201 Squares
- jni初体验
- 知乎:你是如何开始能写python爬虫?
- 如何判断一个点是否在一个多边形内部+三角形有向面积公式
- hdu 5178 pairs
- android:configChanges locale 改语言后,该配置不起作用的解决方案
- Lua封装map
- Python super