1 条题解
-
0
#include <bits/stdc++.h> using namespace std; string s1, s2; int a[1000], b[1000], c[1000], fs, len;
int main() { cin >> s1 >> s2; int len1 = s1.length(), len2 = s2.length(); if (len1 >= len2) { len = len1; } else { len = len2; } for (int i = 0; i < len1; i++) { a[i] = s1[len1 - i - 1] - '0'; } for (int i = 0; i < len2; i++) { b[i] = s2[len2 - i - 1] - '0'; } if (len1 >= len2 && s1 >= s2) { for (int i = 0; i < len; i++) { if (a[i] < b[i]) { a[i + 1]--; a[i] += 10; } c[i] = a[i] - b[i]; } } else { fs = 1; for (int i = 0; i < len; i++) { if (b[i] < a[i]) { b[i + 1]--; b[i] += 10; } c[i] = b[i] - a[i]; } } if (fs == 1) { cout << "-"; } while (c[len] == 0 && len > 0) { len--; } for (int i = len; i >= 0; i--) { cout << c[i]; } }
- 1
信息
- ID
- 941
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 5
- 标签
- 递交数
- 105
- 已通过
- 37
- 上传者