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 ...
随机推荐
- JS 时间与时间戳的相互转换
<script type="text/javascript"> var time = "2015-04-22 21:41:43";//2015-4- ...
- SQL Server数据的导入导出
SQL Server 2008的导入导出服务可以实现不同类型的数据库系统的数据转换.为了让用户可以更直观的使用导入导出服务,微软提供了导入导出向导.导入和导出向导提供了一种从源向目标复制数据的最简便的 ...
- Character Studio
- EF6调用存储过程,返回多个结果集处理
链接:http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram 案例: ...
- 今天是程序员节(Programmer‘s Day)
http://blog.jobbole.com/47787/ 我只想知道他们到底在说神马???
- ios 可变参数(va_list,va_start,va_end)
例如:UIAlertView的init方法中的otherButtonTitles:(NSString *)otherButtonTitles, ...等多个可变参数. ios实现传递不定长的多个参数的 ...
- JS中==和===的区别
1.对于string,number等基础类型,==和===是有区别的 1)不同类型间比较,==之比较“转化成同一类型后的值”看“值”是否相等,===如果类型不同,其结果就是不等 2)同类型比较,直接进 ...
- iOS-开发日志-UIPageControl
UIPageControl 1. numberOfPages // 设置有多少页 默认为0 // 2) 设置页数 [pageControl setNumberOfPages:kImageCount] ...
- WPF简单拖拽功能实现
1.拖放操作有两个方面:源和目标. 2.拖放操作通过以下三个步骤进行: ①用户单击元素,并保持鼠标键为按下状态,启动拖放操作. ②用户将鼠标移到其它元素上.如果该元素可接受正在拖动的内容的类型,鼠标指 ...
- switch case实现两个数的算术运算
方法一: package com.liaojianya.chapter1; import java.util.Scanner; public class SwitchDemo1 { public st ...