1075 数制转换
来源:互联网 发布:莳绘钢笔淘宝 编辑:程序博客网 时间:2024/06/05 16:22
描述
设有一个字符串A$的结构为: A$=’m(n)p’ 其中m为数字串(长度<=20),而n,p均为1或2位的数字串(其中所表达的内容在2-10之间)。 程序要求:从键盘上读入A$后(不用正确性检查),将A$中的数字串m(n进制),以p进制的形式输出。 例如:A$=’48(10)8’ 其意义为:将10进制数48,转换成8进制数输出。 输出结果为:48(10)=60(8)输入
包含多组测试数据 一个字符串A,中间以一个(n)隔开,(n)之前是一个整数m,n表示n进制,(n)之后是一个整数p,表示要将n转换成p进制 每个字符串占一行输出
每个输出占一行 按以下格式输出 m(n)=q(p) 表示n进制的m和p进制的q相等样例输入
48(10)8
样例输出
48(10)=60(8)
解题思路:
先把每一位抽取出来,然后按照进制进行还原,反正最后都是按照十进制来做。接下来再按照新的进纸进行位抽取即可。
#include <stdio.h>#include <math.h>main(){long long m; int n,p;long long result;int a[200];int up;int i;long long t; long long xx; while (scanf("%lld(%d)%d",&m,&n,&p)!=EOF) { t=m; up=0; // printf("%d\n",m); while(m!=0) { a[up]=m%10; up++; m=m/10; // printf("%d\n",a[up-1]); } result=0; xx = 1; for(i=0;i<up;i++) { result=result+xx*a[i]; xx =xx * n; } // printf("%lld\n",result); // printf("%d\n",p); up=0; while(result!=0) { a[up]=result%p; up++; result=result/p; } result=0; xx = 1; for(i=0;i<up;i++) { result=result + xx*a[i]; xx = xx * 10; } printf("%lld(%d)=%lld(%d)\n",t,n,result,p); }}
- 1075 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- 数制转换
- vb.net 两种方式调用存储过程的总结
- current REDO被删的处理
- 死锁避免-银行家算法 模拟
- 数据归档的元数据
- X11,X Window,hello world 例子
- 1075 数制转换
- “无法为更新定位行,一些值可能已在最后一次读取后已更改”问题的解决方法
- An introduction to SOLID principles in OO design
- SDIO 驱动
- 基于ArcGIS Server的ADF的异步回调机制实现基于动态数据显示问题
- 1076 神经网络
- oracle忘记密码的解决方案总结
- 内部稽核与内部控制管理体系关系的探讨
- SDIO架构初解2