Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
103919 万隽宇 二进制小数转十进制 C++ Wrong Answer 1 MS 276 KB 596 2025-01-02 18:53:46

Tests(0/10):


Code:

#include<iostream> // cin\cout\endl #include<cstdio> //scanf()\printf() #include<cstring> // strcpy()\strcat()\strcmp()\strlen()\memset() #include<cmath> //sqrt()\pow()\abs()\ceil()\floor()\max()\min() using namespace std; int main(){ char n[65]; cin>>n; int j=strlen(n),b=0; double a=0.0,c=1; while(n[b]!='.'&&b<j)b++; for(int k=b-1;k>=0;k--){ a+=(n[k]-'0')*c; c=c*2; } c=2.0; for(int i=b+1;i<j;i++){ a+=(n[i]-'0')/c; cout<<(n[i]-'0')/c<<endl; c=c*2; } cout<<a; return 0; }


Run Info:

------Input------
0.111
------Answer-----
0.875
------Your output-----
0.5 0.25 0.125 0.875