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 ...
随机推荐
- JUnit4注解基本介绍
@After If you allocate external resources in a Before method you need to release them after the test ...
- .net+easyui--combobox
一:预定义结构的 select 元素创建组合框(combobox)值固定写死 <select class="easyui-combobox" name="state ...
- MVC小系列(十五)【MVC+ZTree实现对树的CURD及拖拽操作】
根据上一讲的可以加载一棵大树,这讲讲下如果操作这颗大树 <link href="../../Scripts/JQuery-zTree/css/zTreeStyle/zTreeStyle ...
- c语言学习之基础知识点介绍(十八):几个修饰关键字和内存分区
一.几个修饰关键字 全局变量: 全局变量跟函数一样也分为声明和实现.如果是全局变量,实现在它调用之后,那么需要在调用之前进行声明.注意:全局变量的声明只能写在函数外,写在函数就不是全局变量了而是局部变 ...
- Emit学习(1)-Emit概览
一.Emit概述 Emit,可以称为发出或者产生.在Framework中,与Emit相关的类基本都存在于System.Reflection.Emit命名空间下.可见Emit是作为反射的一个元素存在的. ...
- html中可以使用在块级元素<body>中的元素
1.<p></p>当在html页面中需要显示大段文字的时候,可以使用p元素标记每一个段落的边界,需要注意的是,段落是块级元素,只允许包含文本和行内元素. 以下标注的是p中的标准 ...
- Linux消息队列
#include <stdio.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/ms ...
- Launch a Batch File With Windows Installer
Quote from: http://flexerasoftware.force.com/articles/en_US/HOWTO/Q111515 Synopsis This article desc ...
- .net闭包的应用
这里体现出闭包的数据共享 , , , , , , , , , }; ; ; values.ToList().ForEach(s => result1 += s); values.ToList() ...
- nginx方面的书籍资料链接
http://tengine.taobao.org/book/ http://blog.sina.com.cn/s/articlelist_1929617884_0_1.html http://blo ...