1 条题解
-
0
本人是出题者。 突然心血来潮,出了一道题哈哈哈。 我们按照题目模拟即可。记得处理进位。
#include <bits/stdc++.h> using namespace std; int n, mod[20], ans[20]; int main(void) { cin >> n; int x = abs(n),i = 0; while (x > 0) { i++; mod[i] = x % 2; x /= 2; } while (i < 8) { i++; mod[i] = 0; } if (n < 0) mod[8] = 1; else mod[8] = 0; if(n > 0) for (int j = i;j >= 1;j--) cout << mod[j]; else { for (int j = 7;j >= 1;j--) { if (mod[j]) mod[j] = 0; else mod[j] = 1; ans[9 - j] = mod[j]; } ans[1] = mod[8]; ans[8]++; for(int j = 8;j >= 2;j--) { if (ans[j] == 2) { ans[j - 1]++; ans[j] = 0; } } for (int j = 1;j <= 8;j++) cout << ans[j]; cout << ' '; } return 0; }
信息
- ID
- 106
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 6
- 已通过
- 2
- 上传者