Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
28019 | 唐心 | 二进制转R进制 | C++ | Accepted | 2 MS | 784 KB | 772 | 2022-06-12 19:05:57 |
#include<iostream> #include<cmath> #include<cstdio> #include<cstring> using namespace std; char num_to_char(int a) { if(a >= 0 && a<= 9) return a + '0'; else return a + 'A' - 10; } int main() //主函数入口 { int i = 0,temp = 0,n,num = 0,r,s = 0; char str[100] = {0}; char str1[100] = {0}; cin >> str; cin >> r; n = strlen(str); for(i = 0; i < n ; i++) { temp = int(str[i] - '0'); num += temp * pow(2,n-i-1); } if(num == 0) { cout << 0 <<endl ; return 0; } while(num) { temp = num % r; str1[s++] = num_to_char(temp); num /=r; } str1[s] = '\0'; for(i = s-1; i >= 0; i--) { cout << str1[i]; } cout << endl; return 0; //结束整个程序 }