| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 69681 | 何子文 | 十进制小数转二进制 | C++ | Accepted | 1 MS | 284 KB | 573 | 2024-04-06 12:08:33 |
#include <bits/stdc++.h> using namespace std; int main() { double a = 0, x = 0, s = 0; int g = 0; int z = 0; int w[10001]; int c = 0; cin >> a; if (a == 0) { cout << a; return 0; } z = a; x = a - z; if (z == 0) { cout << z; } for (int i = 0; z != 0; i++) { w[i] = z % 2; z = z / 2; c++; } for (int i = c - 1 ; i >= 0; i--) { cout << w[i]; } if (x != 0) cout << "."; while (x != 0) { g++; s = x * 2; cout << (int)s; if (g == 9) break; x = s - (int)s; } return 0; }