确保输出超大数不会出错的题解
2024-12-09 21:13:31
发布于:浙江
21阅读
0回复
0点赞
// 同志们,有一个检测点是输入10000,所以要保证如果结果是一个超级超级超级长长长的数也不能出错!!!!!
#include <iostream>
using namespace std;
const int MAX_DIGITS = 10000;
int main() {
int n;
cin >> n;
int result[MAX_DIGITS] = {0};
result[0] = 66;
int size = 2;
if (n > 1) {
for (int i = 0; i < n - 1; ++i) {
int carry = 0;
for (int j = 0; j < size; ++j) {
int product = result[j] * 2 + carry;
result[j] = product % 10;
carry = product / 10;
}
while (carry) {
result[size++] = carry % 10;
carry /= 10;
}
}
}
for (int i = size - 1; i >= 0; --i) {
cout << result[i];
}
cout << endl;
return 0;
}
这里空空如也
有帮助,赞一个