标签:stream pre for ret amp end 组复制 space eof
#include <iostream> #include <string> #include <cstring> using namespace std; string a1,b1; int a[100001],b[100001],c[100001],t[100001]; int compare(int aa[],int bb[]) { //判断数组大小 if (aa[0]>bb[0]) return 1; if (aa[0]<bb[0]) return -1; for (int i=aa[0]; i>0; i--) { if (aa[i]>bb[i]) return 1; if (aa[i]<bb[i]) return -1; } return 0; } void numcpy(int aa[],int bb[],int l) { //数组复制 for (int i=1; i<=aa[0]; i++) bb[i+l-1]=aa[i]; bb[0]=aa[0]+l-1; } int main() { cin>>a1>>b1; a[0]=a1.size(); b[0]=b1.size(); c[0]=a[0]-b[0]+1; for (int i=1; i<=a[0]; i++) a[i]=a1[a[0]-i]-48; for (int i=1; i<=b[0]; i++) b[i]=b1[b[0]-i]-48; for (int i=c[0]; i>0; i--) { memset(t,0,sizeof(t)); numcpy(b,t,i); while (compare(a,t)>=0) { c[i]++; if (!compare(a,t)) { a[0]=0; continue; } for (int i=1; i<=a[0]; i++) { if (a[i]<t[i]) a[i+1]--,a[i]+=10; a[i]-=t[i]; } while (a[0]>0&&!a[a[0]]) a[0]--; } } while (c[0]>0&&!c[c[0]]) c[0]--; if (!c[0]) cout<<0<<endl; else for (int i=c[0]; i>0; i--) cout<<c[i]; return 0; }
标签:stream pre for ret amp end 组复制 space eof
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/11939236.html