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,生成一个像下 ...
随机推荐
- Caffe安装过程错误处理方法
1. 错误1: fatal error: caffe/proto/caffe.pb.h: No such file or directory 解决方法: You need to generate ca ...
- Java文档注释
文档注释是用于生成API文档,API主要用于说明类.方法.成员变量 javadoc工具 处理文档源文件在类.接口.方法.成员变量.构造器和内部类之前的注释,忽略其他地方的文档注释.而且javadoc工 ...
- 2017年IT互联网圈跑会指南~
啦啦啦~要放假啦,还有十多天就要过年啦,要走亲访友啦!相信大家也是各种胡吃海喝后,啊咧~腰上好像多了好几圈o(>﹏<)o为了让小伙伴们及时制定年后行程(减膘)计划,活动家特此奉上2017年 ...
- 将bat文件或exe程序注册成windows服务
命令行使用sc命令.关于sc命令的详解,请自行查看帮助(sc /?),在此只简单提及如何加入系统服务功能.加入服务:sc create ServiceName binPath= 路径 start= a ...
- SQL sever 创建定时执行任务
在SQL的使用过程中,我们经常要做些数据备份以及定时执行的任务. 这些任务能够帮助我们简化工作过程. 下面我们了解下如何创建一个定时执行的存储过程. 首先我们要打开 SQL server 代理服务 选 ...
- Storm 1.0.0
Storm 1.0.0版本增加了很多新的特性,可用性以及性能也得到了很大的改善,该版本是Storm发展历程上一个里程碑式的版本,主要特点如下. 性能提升 Storm 1.0.0版本最大的亮点就是性能提 ...
- 【jQuery、原生】键盘键入两位小数
jquery的处理办法 <!doctype html> <html lang="en"> <head> <meta charset=&qu ...
- 创建Properties文件
/** * 生成Properties文件 * @param map Properties文件的内容,键值对 * @param path Properties文件生成后存放的路径 * @param pr ...
- Hive 执行计划
执行语句 hive> explain select s.id, s.name from student s left outer join student_tmp st on s.name = ...
- [SOJ]连通性问题
Description 关系R具有对称性和传递性.数对p q表示pRq,p和q是0或自然数,p不等于q.要求写一个程序将数对序列进行过滤,如果一个数对可以通过前面数对的传递性得到,则将其滤去.例如:输 ...