| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 73790 | 彭林江 | 二进制转十进制 | C++ | Accepted | 0 MS | 280 KB | 551 | 2024-05-19 16:54:22 |
#include<bits/stdc++.h> using namespace std; int main(){ // 由于是二进制,所以得用字符串进行输入 string s; cin >> s; int len = s.size(); // 字符串没法直接进行进制转换,所以得将对应的字符串转成整型数组,并且倒序 int a[len]; int j = 0; for(int i = len-1; i >= 0; i--){ a[j] = s[i] - '0'; j++; } int sum = 0; // 利用二进制转十进制的方式;累加就可以了 for(int i = 0; i < len; i++){ sum += pow(2,i) * a[i]; } cout << sum; return 0; }