本文共 1203 字,大约阅读时间需要 4 分钟。
#include#include #include #include using namespace std;int a[5][35],b[5][35],di[5][35],c[35],w[5];string str;int n;void read1(int oli){ cin>>str; while(str[0]<'0'||str[0]>'9') cin>>str; for(int i=1; i<=str.size(); i++) a[oli][30-str.size()+i]=str[i-1]-48;}void read2(int tx){ cin>>str; while(str[0]<'0'||str[0]>'9') cin>>str; for(int i=1; i<=str.size(); i++) b[tx][30-str.size()+i]=str[i-1]-48;}void bj(int xs) //比较{ int i; for(i=1; i<=30; i++) if(b[xs][i]!=di[xs][i]) break; if(b[xs][i]>di[xs][i]) { for(i=1; i<=30; i++) di[xs][i]=b[xs][i]; w[xs]=1; }}void gjd(int zz){ if(w[zz]==0) { cout<<0<<" "; return; } int jw=0,k=1; for(int i=30; i>0; i--) //高精度 if(di[zz][i]-jw>=a[zz][i]) { c[i]=di[zz][i]-jw-a[zz][i]; jw=0; } else { c[i]=di[zz][i]+10-jw-a[zz][i]; jw=1; } while(c[k]==0&&k<=30) //去掉前导0 k++; for(int i=k; i<=30; i++) cout< >n; for(int i=1; i<=n; i++) { memset(b,0,sizeof(b)); read2(1); bj(1); read2(2); bj(2); read2(3); bj(3); } gjd(1); gjd(2); gjd(3); return 0;}
转载地址:http://fjle.baihongyu.com/