Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
67429 冯诚阳 二进制小数转十进制 C++ Accepted 1 MS 276 KB 527 2024-03-16 15:30:07

Tests(10/10):


Code:

#include<iostream> #include<cstring> #include<cmath> using namespace std; int main(){ string str; cin>>str; int len=str.length(); double ans=0; double power=1; int i=0; while(str[i]!='.' && i<len) i++; for(int k=i-1;k>=0;k--){ ans+=(power*(str[k]-'0')); power*=2; } power=2; for(i+=1;i<len;i++){ ans+=((1/power)*(str[i]-'0')); power*=2; } cout<<ans; return 0; }