| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 69670 | 许铭锐 | 十进制小数转二进制 | C++ | Wrong Answer | 0 MS | 272 KB | 426 | 2024-04-06 11:57:59 |
#include<bits/stdc++.h> using namespace std; int cnt=0; int main(){ int a[32]={0}; double n; cin>>n; int z=n; if(n==0){ cout<<0; } double x=n-z; while(z!=0){ a[cnt++]=z%2; z/=2; } for(int i=cnt-1;i>=0;i--){ cout<<a[i]; } if(x==0){ return 0; }else{ cout<<"."; } for(int i=1;i<=9;i++){ x=x*2; cout<<(int)x; x-=(int)x; if(x==0){ break; } } return 0; }
------Input------
0.125
------Answer-----
0.001
------Your output-----
.001