上网查了一下进制转换的算法,发现一个性能比较好的:m进制转换成n进制,先用例如62进制ABC转换成10进制,就是用余位c(第一个数余位数值为0)乘以原基数from,加上A表示的数值,然后得到一个数,对to(要转换的进制)取商替换字符A,注意要用相应字符替换相应位这里是s[0],然后取模作为计算下位时的余位,当计算到最后一位时把余位存起来,因为这就是要准换成的数字的第一位,最后逆序输出就行。最终直到s字符串所有位都是0,反复操作过程中可以改变遍历的下限也就是从第一个不为0的地方开始乘基数取模。

代码:

 #include<stdio.h>
#include<string.h>
#define N 10010 char s[N],back[N]; int to_10(char ch)
{
if(ch<='')
return ch-'';
if(ch<='Z')
return ch-'A'+;
return ch-'a'+;
} char toch[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int ans[N]; int main(void)
{
int tcase,from,to;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%d%d%s",&from,&to,s);
strcpy(back,s);
int i,c=,t,count=,low=,tag=;
int len=strlen(s);
while()
{
if(low==len)//
break;
c=tag=;
for(i=low; i<len; i++)
{
t=c*from+to_10(s[i]);
s[i]=toch[t/to];
if(t/to)
tag=;
if(!tag&&t/to==)
low=i+;
c=t%to;
if(i==len-)
ans[count++]=c;
}
}
printf("%d %s\n",from,back);
printf("%d ",to);
while(count--)
putchar(toch[ans[count]]);
puts("\n");
}
return ;
}

POJ_1220_Nmber Sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. 无法启动调试--未安装 Silverlight Developer 运行时。请安装一个匹配版本。

    引自:http://www.cnblogs.com/chillsrc/archive/2010/06/28/1766816.html 安装完VS2010中文版之后,又安装了Silverlight4_T ...

  2. 【转】【SQL SERVER】怎样处理作业中的远程服务器错误(42000)

    (SQL SERVER)怎样处理作业中的远程服务器错误(42000) 问: 1.我创建了一个链接服务器. 2.在两台服务器之间创建了新的SQL用户. 3.编写了访问链接服务器的SQL语句,执行成功. ...

  3. C#学习笔记(4)

    今天先把上几个系列的做一个总结,在这里给出一个面向对象版的简易计算器(重在理解面向对象的思想). 1.首先定义一个计算器类(类库)(Calculator) public abstract class ...

  4. C++ 变量转换

    atoi,atol,strtod,strtol,strtoul实现类型转换2006-02-13 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://ivanvic.blogb ...

  5. c编程:提示用户输入一个0—9的数字进行猜测电脑产生的随机数。一共有三次机会。

    // //  main.c //  使用c语言进行编程: 题目:由电脑生成一个由0-9之间的随机数,提示用户也输入一个数字进行猜测.当猜测三次仍不中的时候结束程序. 编译环境:Xcode6.3 特别介 ...

  6. linux命令行执行db2存储过程

    存储过程代码如下: CREATE PROCEDURE proc_sum2(IN n INT,OUT sum INT,OUT j INT) BEGIN DECLARE i INT; ; ; ; WHIL ...

  7. linux 搭建pptpd vpn(转,备忘)

    1.第一步需要安装PPTP,以用来提供VPN服务.sudo apt-get install pptpd注:如果有问题的话比如提示找不到之类的,apt-get update 一下应该就可以了,然后再来一 ...

  8. checkbox 选择一个checkbox,其他checkbox也会选择

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  9. STL:remove和erase区别

    C++ STL中的remove和erase函数曾经让我迷惑,同样都是删除,两者有什么区别呢? vector中的remove的作用是将等于value的元素放到vector的尾部,但并不减少vector的 ...

  10. layerX && layerY

    转载:https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/layerX UIEvent.layerX 非标准 这个属性是非标准的属性,并且 ...