3532 - 程序员之路

程序员(英文Programmer)是从事程序开发、维护的专业人员。一般将程序员分为程序设计人员和程序编码人员,但两者的界限并不非常清楚,特别是在中国。软件从业人员分为初级程序员、高级程序员、系统分析员,系统架构师,测试工程师五大类。
----摘自百度百科《程序员》词条。

也许,你并不会修电脑,甚至不会重装windows!
但是你依然在程序员之路上疾跑,并且伺机待发着,时刻准备着:目标,大四狗!为毕业献身!在那灿烂的六月毕业季大喊一声:“起飞~~~啊哈哈哈哈!”

你一刻也没有忘记,计算机中的数字是用二进制表达的,而非十进制。
但是,为了学长,为了天堂大笑,你不能只会十进制转换为二进制!

好了,下面,请你完成这个进制转换的问题。

题目输入

多组输入数据,每组数据包含两个整数k(int范围内)和x(2<=x<=36)


题目输出

对于每组输入数据,输出对应的x进制数,进制转换中数字10用A表示,11用B表示,以此类推。


输入/输出样例

题目输入

8 2
23 12​

题目输出

1000
1B

C++解答

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cassert>
#include <complex>
#include <ctime>

#define clr(x,a) memset(x,a,sizeof(x))
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define repeat(i, a, b) for(int i=(a);i<=(b);i++)
#define all(v) (v).begin(), (v).end()
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define X first
#define Y second



using namespace std;

const int MAX=40;
int num[MAX];

void turn (int n,int k){
    int cnt=0;
    if (n<0){cout<<'-';n=-n;}
    while (n){
        num[++cnt]=n%k;
        n/=k;
    }
    for (int i=cnt;i>=1;i--)
        if (num[i]>=10)
            cout<<char (num[i]-10+'A');
        else
            cout<<num[i];
    cout<<endl;
}
int main () {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //srand(time(NULL));
    int n,k;
    while (cin>>n>>k) {
        turn(n,k);
    }
    return 0;
}

时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题