Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
94049 | 孙嘉言 | 十进制小数转二进制 | C++ | Accepted | 1 MS | 276 KB | 471 | 2024-10-19 17:32:32 |
#include <iostream> #include <cstring> #include <cmath> using namespace std; int main(){ double str; int a[1001],i=0; cin>>str; int x=str; double y=str-x; if(x==0) cout<<0; while(x!=0){ a[i]=x%2; x/=2; i++; }for(int k=i-1;k>=0;k--) cout<<a[k]; if(y!=0){ cout<<'.'; while(y!=0){ y*=2; cout<<(int)y; y-=(int)y; } } cout<<endl; return 0; }