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 < x^120), 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

Analysis of ideas

利用短除法 poj1220原题

Accepted code


#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 1100; int getnum(char ch) //字符转数字
{
if(ch <= '9') return ch-'0';
else if(ch <= 'Z') return 10+ch-'A';
else return 36+ch-'a';
} char getch(int num) //数字转字符
{
if(num <= 9) return num+'0';
else if(num <= 35) return num-10+'A';
else return num-36+'a';
} int n,m;
char str1[maxn],str2[maxn];
int t[maxn],ans[maxn]; void solve()
{
int len = strlen(str1); for(int i = 0; i < len; i++) //先把字符串变成数组,高位->低位
t[i] = getnum(str1[i]); int j = 0,k = 0;
while(j < len)
{
for(int i = j; i < len-1; i++) //除以m,把余数加到下一位
{
t[i+1] += t[i] % m * n;
t[i] /= m;
} ans[k++] = t[len-1]%m; //个位数余m
t[len-1] /= m; while(j < len && !t[j]) j++; //最高位是0,j++
} for(int i = 0; i < k; i++) //逆序变成字符串
{
str2[i] = getch(ans[k-i-1]);
}
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t;
cin(t);
while(t--)
{
mem(ans,0),mem(str2,0); //wa
cin>>n>>m;
cin>>str1;
solve();
cout<<n<<' '<<str1<<endl;
cout<<m<<' '<<str2<<endl<<endl;
} }

icpc 银川 I. Base62 任意进制的转换 短除法的更多相关文章

  1. C#十进制与任意进制的转换

    /// <summary> /// 将十进制转换为指定的进制 /// </summary> /// <param name="Val">十进制值 ...

  2. python的十进制与任意进制的转换

    将任意进制转换成十进制 ", 8)) # 表示把8进制的54转换成十进制数并输出结果. # 8可以是2.8,10,16等进制数 将十进制转换成任意进制 def f(n,x): #n为待转换的 ...

  3. java 的任意进制间转换(很方便)

    import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = n ...

  4. java 的任意进制间转换

    直接上代码: public class Main { public static void main(String[] args) { // TODO Auto-generated method st ...

  5. (高精度运算4.7.26)POJ 1220 NUMBER BASE CONVERSION(高精度数的任意进制的转换——方法:ba1----->10进制----->ba2)

    package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_1220_ ...

  6. C语言之任意进制的转换

    我们都知道转换进制是一个让人比较头疼的事情,下面我的代码不是最好的,也就仅仅是一个思路而已,至少我认为使用栈来进行进制转换是比较合适的一种方法,好了,不多叙述了. #include<stdio. ...

  7. C#实现整型数据字任意编码任意进制的转换和逆转换

    实现如下: using System; using System.Collections.Generic; using System.Linq; using System.Text;  namespa ...

  8. Python版任意进制转换

    def decimalToAny(num,n): baseStr = {10:"a",11:"b",12:"c",13:"d&qu ...

  9. itoa()、atoi()、任意进制转换

    头文件:<stdlib.h> itoa --功能:将任意类型的数字转换为字符串.在<stdlib.h>中与之有相反功能的函数是atoi. atoi----功 能: 将字符串转换 ...

随机推荐

  1. 04 IO流(二)——IO类的记忆方法、使用场景

    关于IO流以前写的PPT式笔记请跳转:https://blog.csdn.net/SCORPICAT/article/details/87975094#262___1451 IO流的主要结构 记忆方法 ...

  2. 使用uiautomator 截图

    1)PC与移动设备建立连接. 2)找到ADB的安装路径,双击启动uiautomator. 路径:D:\ProgramFiles\adt-bundle-windows-x86_64-20140702\a ...

  3. 最简容器化动手小实践——再战flappybird

    <Flappy Bird>是一名越南开发者所开发的游戏,这款游戏的主要内容是帮助一只小鸟穿越水管的层层阻碍,玩家所需要的只是点击屏幕从而调整小鸟的高度.而令这款游戏与众不同的是,这款游戏的 ...

  4. hdu 6661 Acesrc and String Theory (后缀数组)

    大意: 求重复$k$次的子串个数 枚举重复长度$i$, 把整个串分为$n/i$块, 如果每块可以$O(1)$计算, 那么最终复杂度就为$O(nlogn)$ 有个结论是: 以$j$开头的子串重复次数最大 ...

  5. Educational Codeforces Round 64 (Div. 2)

    A.3*3讨论即可,注意正方形套圆套三角形只有6个点. #include<cstdio> #include<cstring> #include<iostream> ...

  6. MyBatis整合Spring+SpringMVC搭建一个web项目(SSM框架)

    本文讲解如何搭建一个SSM架构的web站点 [工具] IDEA.SqlYog.Maven [简述] 该项目由3个模块组成:dao(数据访问层).service(业务处理层).web(表现层) dao层 ...

  7. 【es6】promise

    一.什么是promise?我们用promise解决什么样的问题 promise是异步编程的一种解决方案:从语法上来说,Promise是一个对象,从他可以获取异步操作的信息:从本意上讲,它是承诺,它承诺 ...

  8. ABP 基于DDD的.NET开发框架 学习(二)创建实体

    1.创建模型类打开.Core项目,新建新建一个项目文件夹(Demo);为了演示表关联及外键的使用,创建两个类:创建类ClothesCategoty.csusing Abp.Domain.Entitie ...

  9. 这些方面做好了才能叫运营-App运营日常

    现在APP的开发推广是时代的潮流,同时也是不少企业的难题.现在我们就来谈谈APP运营的一些问题. 1. 基础运营正常维护产品最日常.最普通的工作,如APP应用包在各大应用市场提交上传等,如安卓渠道,包 ...

  10. 50个Sql语句实战

    /* 说明:以下五十个语句都按照测试数据进行过测试,最好每次只单独运行一个语句. 问题及描述:--1.学生表Student(S#,Sname,Sage,Ssex) --S# 学生编号,Sname 学生 ...