HDU 1335 Basically Speaking(进制转换)
It will have a 7-digit display.
Its buttons will include
the capital letters A through F in addition to the digits 0 through 9.
It
will support bases 2 through 16.
one base conversion per line. There will be three numbers per line. The first
number will be the number in the base you are converting from. The second number
is the base you are converting from. The third number is the base you are
converting to. There will be one or more blanks surrounding (on either side of)
the numbers. There are several lines of input and your program should continue
to read until the end of file is reached.
would appear on the display of the calculator. The number should be right
justified in the 7-digit display. If the number is to large to appear on the
display, then print "ERROR'' (without the quotes) right justified in the
display.
#include<stdio.h>
#include<cstring>.
#include<iostream>
using namespace std;
char s[];
int a,b;
int len,i,j;
long long c;
char ans[];
int f(int j)
{
int res=;
while(j--)
res*=a;
return res;
}
int main()
{
while(cin>>s>>a>>b)
{
len=strlen(s);
c=;
for(i=len-,j=;i>=;i--,j++)
{
if(s[i]>=''&&s[i]<='')
c+=(s[i]-'')*f(j);
else
c+=(s[i]-'A'+)*f(j);
}
//从a进制转化为十进制c
//cout<<c<<" ";//
//接下来从十进制c转换为b进制字符串ans
for(i=;i<;i++)
{
if(c<)break;
ans[i]=''+(c%b);
c/=b;
}
int len1=i;
//cout<<len1<<" ";//
if(len1>)cout<<" ERROR"<<endl;
else
{
for(i=;i<=-len1;i++)cout<<" ";
for(i=len1-;i>=;i--)
{
if(ans[i]>=''&&ans[i]<='')
cout<<ans[i];
else
printf("%c",ans[i]-''-+'A');
}
cout<<endl;
}
}
return ;
}
HDU 1335 Basically Speaking(进制转换)的更多相关文章
- HDOJ 1335 Basically Speaking(进制转换)
Problem Description The Really Neato Calculator Company, Inc. has recently hired your team to help d ...
- HDU 2097 Sky数 进制转换
解题报告:这题就用一个进制转换的函数就可以了,不需要转换成相应的进制数,只要求出相应进制的数的各位的和就可以了. #include<cstdio> #include<string&g ...
- HDU 5050 Divided Land(进制转换)
题意 给你两个二进制数m,n 求他们的最大公约数 用二进制表示 0<m,n<2^1000 先把二进制转换为十进制 求出最大公约数 再把结果转换为二进制 数比較大要用到大数 ...
- HDU 2031 进制转换(10进制转R进制)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2031 进制转换 Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 2031 进制转换(栈思想的使用)
进制转换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1877 又一版 A+B(进制转换)
看了http://lovnet.iteye.com/blog/1690276的答案 好巧妙的方法 递归实现十进制向m进制转换 #include "stdio.h" int m; v ...
- CF 552C 进制转换
http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...
- 进制转换,杭电0j-2031
进制转换,杭电0j-2031原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=2031 [Problem Description] 输入一个十进制数N,将它 ...
- SQL Server 进制转换函数
一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...
随机推荐
- .net在网页中生成二维码和条形码
二维码: 1.下载ThoughtWorks.QRCode.dll文件 2.创建Web项目,添加引用刚才下载的文件 3.在项目中添加aspx窗体,编写代码如下 <%@ Page Language= ...
- SHELL中,如何分割字符串
done.csv中,形如 amoy9812@163.com的数据 #!/bin/shwhile read linedo ar=(${line//@/ }) echo ${ar[0]} #说明:分解出账 ...
- python 数据清洗之字符串处理
在数据分析中,特别是文本分析中,字符处理需要耗费极大的精力, 因而了解字符处理对于数据分析而言,也是一项很重要的能力. 字符串处理方法 首先我们先了解下都有哪些基础方法 首先我们了解下字符串的拆分sp ...
- DrawingCombiner——CAD图纸批量合并软件
DrawingCombiner是一款CAD图纸批量合并软件,可以批量合并多个dwg或dxf文件为单个dwg文件,并可以设置合并后的排列方式. 此程序附属MagicTable(可到依云官网下载:http ...
- python3 列表 函数
python3中list的所有函数 list是有序的,元素个数无限的,元素类型多样的,可变的 增加 # 'append', 增加对象# 'insert', 指定位置增加# 'extend', 增加可迭 ...
- 【安装】python3.4版安装与2.x共存问题
首先,到官网去下载python3.x版,这里推荐3.4以上的版本,自带pip库,以后不用自己另外下载 3.4.4版: https://www.python.org/downloads/release/ ...
- 【优先队列】-HDU4546比赛难度
比赛难度 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- 何为PostgreSQL?
PostgreSQL 是以加州大学伯克利分校计算机系开发的 POSTGRES, Version 4.2 为基础的对象关系型数据库管理系统(ORDBMS).POSTGRES 领先的许多概念只是在非常迟的 ...
- 在ubuntu14.04上安装openstack mitaka
最近在工作环境安装部署了juno版本,在GE口测试网络性能不太满意,发现mitaka版本支持ovs-dpdk,于是抽时间安装实验一番. 参考官网的安装文档,先准备将mitaka版本安装好再配置ovs. ...
- AndroidAsyncHttp 临时修复 JsonHttpResponseHandler 避免死循环
由于 AndroidAsyncHttp 1.4.4 的 JsonHttpResponseHandler 存在死循环的 BUG,1.4.5 版本发布不知道要何时,所以只能临时替换该类来修复这个错误. ...