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 ...
随机推荐
- ArrayList的深度copy和浅度拷贝
ArrayList的浅度拷贝方式: 通过Collections.copy方法实现浅度拷贝 ArrayList<GuideGroup> questionGuideGroupList = ne ...
- IT牛人博客
IT牛人博客,参见:http://blog.csdn.net/freebird_lb/article/details/8210276 团队技术博客 淘宝UED淘宝用户体验团队 淘宝核心系统淘宝核心系统 ...
- MySQL基本查询语句
创建一张表 create table user ( id ) not null, name ) not null, birthDate date not null, gender ) not null ...
- java中substring和indexof() 和lastindexof()
java中substring和indexof() 和lastindexof() str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字 ...
- ACM——大数相加
大数加法 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte 总提交:2085 测试通过:543 描述 求两个非负整数( ...
- Lucene/Solr开发经验
1.开篇语2.概述3.渊源4.初识Solr5.Solr的安装6.Solr分词顺序7.Solr中文应用的一个实例8.Solr的检索运算符 [开篇语]按照惯例应该写一篇技术文章了,这次结合Lucene/S ...
- iOS 设置图片imageView圆角——对图片进行裁剪
以前设置图片圆角总是把imageView设置成圆形,然后设置maskToBounds为YES,其实这样处理很消耗性能,图片多了之后比较卡,最好将图片进行裁剪后显示:这里有个分类可以用: UIImage ...
- sharepoint2013 新建母板页 新建页面布局 关联母板页和页面布局
1 母板页的应用和layout(页面布局)的创建和应用 母板页上传:将准备好的html和样式 通过spd中的导入方式导入模版html, 导入后: 然后在网站设置中进行转换为母板页. 随后编辑 ...
- 哥德巴赫猜想证明(C语言实现50以内的正偶数证明)
<一>哥德巴赫猜想内容: 一个充分大的偶数(大于或等于6)可以分解为两个素数之和. <二>实现要点: 要点: 判断素数(质数):除了1和本身没有其他约数. 最小的质数:2 判断 ...
- leetcode problem 32 -- Longest Valid Parentheses
Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length ...