给定两个非负整数,请你计算 它们 的商和余数。
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> a, c; int b; int div () { int t = 0; for (int i = a.size() - 1; i >= 0; i--) { t = t * 10 + a[i]; c.push_back(t / b); t %= b; } reverse(c.begin(), c.end()); while (c.size() > 1 && c.back() == 0) c.pop_back(); return t; } int main() { string x; cin >> x >> b; for (int i = x.size() - 1; i >= 0; i--) a.push_back(x[i] - '0'); int t = div (); for (int i = c.size() - 1; i >= 0; i--) cout << c[i]; cout << endl << t << endl; return 0; }
标签:include,高精度,int,back,--,push,除法,size From: https://www.cnblogs.com/leetothemoon/p/16939714.html