Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
110562 王思颜 二进制小数转十进制 C++ Accepted 1 MS 280 KB 514 2025-02-22 12:12:00

Tests(10/10):


Code:

#include<bits/stdc++.h> using namespace std; string a; int main() { cin>>a; int n = a.size(); int xsd = -1,j = 0; double x = 0; for (int i = 0;i < n;i++){ if (a[i] == '.'){ xsd = i; break; } } for (int i = xsd - 1;i >= 0;i--){ if (a[i] != '0'){ x += (a[i] - 48) * pow(2,j); } j++; } if (xsd != -1){ for (int i = xsd + 1;i < n;i++){ if (a[i] != '0'){ x += (a[i] - 48) * pow(2,xsd - i); } } cout<<x; } else{ cout<<x; } return 0; }