首页 > 其他 > 详细

ICPC2019银川Base62

时间:2021-05-13 20:06:05      阅读:12      评论:0      收藏:0      [点我收藏+]

Problem Description

  As we already know, base64 is a common binary-to-text encoding scheme. Here we define a special series of positional systems that represent numbers using a base (a.k.a. radix) of 2 to 62. The symbols ‘0’ – ‘9’ represent zero to nine, and ‘A’ – ‘Z’ represent ten to thirty-five,and ‘a’ – ‘z’ represent thirty-six to sixty-one. Now you need to convert some integer z in base x into base y.

Input

  The input contains three integers x; y (2 ≤ x; y ≤ 62) and z (0 ≤ z < x120), where the integer z is given in base x.

Output

  Output the integer z in base x.

Sample Input

  16 2 FB

Sample Output

  11111011

 

题解

  直接将任意进制数转为任意进制数,把样例带进去手推一遍你就明白了。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
char str1[2000005],str2[2000005];
int x[2000005],l,ans[2000005],n,m,k;
void trans()
{
    l=strlen(str1);
    for(int i=0;i<l;i++)
    {
        if(str1[i]>=0&&str1[i]<=9)x[i]=str1[i]-0;
        else if(str1[i]>=A&&str1[i]<=Z)x[i]=str1[i]-A+10;
        else if(str1[i]>=a&&str1[i]<=z)x[i]=str1[i]-a+36;
    }
}
void trans2()
{
    int j=0;
    for(int i=k-1;i>=0;i--)
    {
        if(ans[i]>=0&&ans[i]<=9)str2[j]=ans[i]+0;
        else if(ans[i]>=10&&ans[i]<=35)str2[j]=ans[i]-10+A;
        else if(ans[i]>=36&&ans[i]<=62)str2[j]=ans[i]-36+a;
        j++; 
    }
}
int main()
{
    int j=0;k=0;
    scanf("%d %d %s",&n,&m,str1);
    trans();
    while(j<l)
    {
        for(int i=j;i<l-1;i++)
        {
            x[i+1]+=x[i]%m*n;
            x[i]/=m;
        }
        ans[k]=x[l-1]%m;k++;
        x[l-1]/=m;
        while(x[j]==0&&j<l)j++;
    }
    trans2();
    cout<< str2;
    return 0;
} 

 

 

ICPC2019银川Base62

原文:https://www.cnblogs.com/wisdom-jie/p/14765137.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!