#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> div(vector<int>& A, int& b, int& r) { vector<int> C; r = 0;//r为余数 for (int i = A.size() - 1; i >= 0; i--) { r = r * 10 + A[i]; C.push_back(r / b); r = r % b; } reverse(C.begin(), C.end());//交换容器内的元素顺序 while (C.size() > 1 && C.back() == 0) C.pop_back(); return C; } int main() { string a; int b,r; cin >> a >> b; vector<int> A; for (int i = a.size() - 1; i >= 0; i--) A.push_back(a[i] - '0'); auto C = div(A, b, r); for (int i = C.size() - 1; i >= 0; i--) cout << C[i]; cout << endl << r << endl; return 0; }
标签:include,高精度,int,back,--,vector,除法,size From: https://www.cnblogs.com/muzhaodi/p/17731567.html