题目大意:
给定两个不超过500位的数,计算他们的乘积
http://codevs.cn/problem/3117/
题解:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; char a[501]; char b[501]; int tmp[1002] = {0}; int main() { cin >> a >> b; int la = strlen(a); int lb = strlen(b); for(int i = 0; i < la; i++) { for(int j = 0; j < lb; j++) { tmp[i+j] += (a[i] - '0')*(b[j] - '0'); } } int len = la + lb - 2; for(int i = len; i > 0; i--) { if(tmp[i] >= 10) { tmp[i-1] += tmp[i]/10; tmp[i] = tmp[i] % 10; } } int i = 0; while(len--) cout << tmp[i++]; cout << tmp[i] << endl; return 0; }