A2.cpp 764 B

123456789101112131415161718192021222324252627
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. string a, b;
  5. while (cin >> a >> b) {
  6. reverse(a.begin(), a.end());
  7. reverse(b.begin(), b.end());
  8. if (a == "0" || b == "0") {
  9. cout << "0" << endl;
  10. continue;
  11. }
  12. vector<int> c(a.size() + b.size(), 0);
  13. for (size_t i = 0; i < a.size(); i++)
  14. for (size_t j = 0; j < b.size(); j++)
  15. c[j + i] += (a[i] - '0') * (b[j] - '0');
  16. for (size_t i = 0; i < c.size(); i++) {
  17. c[i + 1] += c[i] / 10;
  18. c[i] = c[i] % 10;
  19. }
  20. if (c.back() == 0)c.erase(c.end() - 1);
  21. copy(c.rbegin(), c.rend(), ostream_iterator<int>(cout, ""));
  22. cout << endl;
  23. }
  24. return 0;
  25. }