01:数制转换
来源:互联网 发布:java前端和后端哪个好 编辑:程序博客网 时间:2024/06/05 01:14
01:数制转换
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
求任意两个不同进制非负整数的转换(2进制~16进制),所给整数在long所能表达的范围之内。
不同进制的表示符号为(0,1,...,9,a,b,...,f)或者(0,1,...,9,A,B,...,F)。- 输入
- 输入只有一行,包含三个整数a,n,b。a表示其后的n 是a进制整数,b表示欲将a进制整数n转换成b进制整数。
a,b是十进制整数,2 =< a,b <= 16。 - 输出
- 输出包含一行,该行有一个整数为转换后的b进制数。输出时字母符号全部用大写表示,即(0,1,...,9,A,B,...,F)。
- 样例输入
15 Aab3 7
- 样例输出
210306
- 来源
- 2005~2006医学部计算概论期末考试
- 分析: 水题。。。。。水。。。。。
#include <stdio.h>#include <iostream>#include <stack>#include <string.h>#include <queue>#include <cmath>#include <vector>#include <algorithm>#include <map>#include <set>#include <string>using namespace std;typedef long long LL;#define MAX 1001//int a[MAX][MAX];//int b[MAX][MAX];//int res[MAX][MAX];//int n, m;char c[MAX];void fun(int a_Before, string str_Before, int b_After){ for(int i = 0; i < str_Before.size(); i++){ if(str_Before[i] >= 'A' && str_Before[i] <= 'Z'){ str_Before[i] += 32; } } LL sum = 0; int j = str_Before.size(); for(int i = 0; i < str_Before.size(); i++){ if(str_Before[i] >= 'a' && str_Before[i] <= 'z'){ sum += (str_Before[i] - 'a' + 10) * pow(a_Before, --j); }else { sum += (str_Before[i] - '0') * pow(a_Before, --j); } } if(sum == 0){ cout << "0" << endl; return; } //cout << sum << endl; j = 0; do{ LL yushu = sum % b_After; if(yushu <= 9){ c[j++] = yushu + '0'; }else { switch(yushu){ case 10: c[j++] = 'A'; break; case 11: c[j++] = 'B'; break; case 12: c[j++] = 'C'; break; case 13: c[j++] = 'D'; break; case 14: c[j++] = 'E'; break; case 15: c[j++] = 'F'; break; } } sum /= b_After; }while(sum != 0); int len = strlen(c); for(int i = len - 1; i >= 0; i--){ cout << c[i]; } cout << endl;}int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int a_Before; string str_Before; int b_After; cin >> a_Before >> str_Before >> b_After; fun(a_Before, str_Before, b_After); return 0;}
阅读全文
0 0
- 01:数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- C++集合操作之集合交集:std::set_intersection
- vim插件管理器Vundle的安装及使用
- 新建workspace时new只有JPA
- HDU 5883 The Best Path(欧拉通路与欧拉回路)
- HDU 5135 Little Zu Chongzhi's Triangles (2014年广州赛区现场赛I题)
- 01:数制转换
- js动态增删元素方法
- Android--音频开发--信号从麦克风到扬声器的处理流程
- CRC校验程序
- 用python写一个简单的倒计时软件
- 100
- 101
- 102
- 103