145 条题解
-
-1
本蒟蒻啥都不会,只能贡献一份小小的码风优良的代码```language
#include <iostream> using namespace std; const int MAX = 1000; void change(const string &a1, int a[], int len) { for (int i = 0; i < len; i++) { a[i] = a1[len - i - 1] - '0'; } } int main() { string a1, b1; cin >> a1 >> b1; int lena = a1.size(), lenb = b1.size(); int a[MAX] = {}, b[MAX] = {}, c[MAX] = {}, cf = 0; change(a1, a, lena); change(b1, b, lenb); int lenc = lena; if (lenb > lena) { lenc = lenb; } for (int i = 0; i <= lenc; i++) { c[i] = a[i] + b[i] + cf; if (c[i] >= 10) { cf = 1; c[i] -= 10; } else { cf = 0; } } int i = lenc; if (c[i] == 0) { i--; } for (i; i >= 0; i--) { cout << c[i]; } return 0; }
信息
- ID
- 56
- 时间
- 1000ms
- 内存
- 1024MiB
- 难度
- 1
- 标签
- 递交数
- 9074
- 已通过
- 4044
- 上传者