Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
99898 任斌 二进制小数转十进制 C++ Accepted 1 MS 276 KB 338 2024-12-01 10:11:42

Tests(10/10):


Code:

#include<bits/stdc++.h> using namespace std; int main() { string str; cin>>str; int len=str.length(); int i=0; double a=0,b=0,p=1; while(str[i]!='.'&& i<len)i++; for(int j=i-1;j>=0;j--){ a+=p*(str[j]-'0'); p*=2; } p=2; for( i+=1;i<len;i++){ a+=(1/p)*(str[i]-'0'); p*=2; } cout<<a; return 0; }