POJ_1220_Nmber Sequence
上网查了一下进制转换的算法,发现一个性能比较好的: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的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [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 ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- Scala中class和object的区别
1.class scala的类和C#中的类有点不一样,诸如: 声明一个未用priavate修饰的字段 var age,scala编译器会字段帮我们生产一个私有字段和2个公有方法get和set ,这和C ...
- com.sun.org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException
在日志中, 查看导入的包是否是 import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
- [02] Oracle简单单行函数(字符+数值+日期+转换+通用)
1. 字符函数 --upper(str), lower(str):将str转换成大,小写 select upper('hello') as x1, lower('HELlo') as x2 from ...
- js控制文本框输入数字和小数点等
1.文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafte ...
- Windows下管理Python安装包
Pip:A tool for installing and managing Python packages. Pip在Python环境中的地方就相当于Ubuntu环境中的apt-get.以及Mac系 ...
- Codevs 1217 借教室 2012年NOIP全国联赛提高组
1217 借教室 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在大学期间,经常需要租借教 ...
- 【CODECHEF】【phollard rho + miller_rabin】The First Cube
All submissions for this problem are available. Read problems statements in Mandarin Chinese and Rus ...
- C#使用Json
AJAX传递复杂数据如果自己进行格式定义的话会经历组装.解析的过程,因此AJAX中有一个事实上的数据传输标准JSon. Json将复杂对象序列化为一个字符串,在浏览器端再将字符串反序列化为JavaSc ...
- MySQL分库分表备份脚本
MySQL分库备份脚本 #脚本详细内容 [root@db02 scripts]# cat /server/scripts/Store_backup.sh #!/bin/sh MYUSER=root M ...
- js实现幻灯片播放图片示例代码
幻灯片播放图片的效果想必大家都有见到过吧,下面有个不错的示例,感兴趣的朋友可以参考下 复制代码代码如下: <select id="img_date" style=" ...