Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
3858 | 吴奕希 | 十进制小数转二进制 | C++ | Wrong Answer | 0 MS | 268 KB | 539 | 2024-07-13 18:37:34 |
# include<iostream> using namespace std; int a; double b,c; string s1, s2; int main(){ cin>>b; a=b; c=b-a; while(a>0){ s1 = char(a%2+48)+s1; 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(c==0){ if(s1=="")cout<<"0"; else cout<<s1; } else if(s1=="")cout<<"0."+s2; else cout<<s1+'.'+s2; return 0; }
------Input------
36.0625
------Answer-----
100100.0001
------Your output-----
100100.1