Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
69679 何子文 十进制小数转二进制 C++ Wrong Answer 1 MS 280 KB 556 2024-04-06 12:06:38

Tests(5/10):


Code:

#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]; } cout << "."; while (x != 0) { g++; s = x * 2; cout << (int)s; if (g == 9) break; x = s - (int)s; } return 0; }


Run Info:

------Input------
4.0
------Answer-----
100
------Your output-----
100.