#include <bits/stdc++.h> using namespace std; int main(){ string a,b; cin>>a>>b; vector<int> x,y; for(int i = a.size()-1;i>=0;i--){ x.push_back(a[i]-'0'); } for(int i = b.size()-1;i>=0;i--){ y.push_back(b[i]-'0'); } bool f = true; int j = 0,sum = 0; while(f){ for(int i = 0;i<x.size();i++){ if(i>=y.size()){ y.push_back(0); } if(y[i]>x[i]){ x[i+1] -= 1; x[i] += 10; } j = x[i]-y[i]; x[i] = j; j /= 10; } if(x.size()>y.size()){ f = true; }else if(x.size()>y.size()){ f = false; }else{ for(int i = x.size()-1;i>=0;i--){ if(x[i]>y[i]){ f = true; break; }else if(y[i]>x[i]){ f = false; break; } } } sum++; } cout<<sum<<" "; bool l = false; for(int i = x.size()-1;i>=0;i--){ if(x[i]!=0 || l){ cout<<x[i]; l = true; } } return 0; }
标签:高精度,int,back,else,--,size From: https://www.cnblogs.com/wangyihang-xh/p/18328794