Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
3849 | 吴奕希 | 十进制小数转二进制 | C++ | Wrong Answer | 0 MS | 264 KB | 436 | 2024-07-13 18:30:23 |
# include<iostream> using namespace std; int a; double b; string s1, s2; int main(){ cin>>b; a=b; while(a>0){ s1 += char(a%2+48); a /= 2; } for(int i = 0; i < 9&&b-int(b)!=0.0; i++){ b = b-int(b); b*=2; s2 = char(int(b)+48)+s2; } while(s2[s2.size()-1]=='0')s2.erase(s2.size()-1, 1); if(b==0)cout<<"0"; else cout<<s1+'.'+s2; return 0; }
------Input------
254.99609375
------Answer-----
11111110.11111111
------Your output-----
01111111.11111111