博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ---4278 Faulty Odometer[进制转化]
阅读量:6902 次
发布时间:2019-06-27

本文共 1820 字,大约阅读时间需要 6 分钟。

 

Faulty Odometer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 222    Accepted Submission(s): 155

Problem Description
  You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from the digit 2 to the digit 4 and from the digit 7 to the digit 9, always skipping over the digit 3 and 8. This defect shows up in all positions (the one's, the ten's, the hundred's, etc.). For example, if the odometer displays 15229 and the car travels one mile, odometer reading changes to 15240 (instead of 15230).
 

 

Input
  Each line of input contains a positive integer in the range 1..999999999 which represents an odometer reading. (Leading zeros will not appear in the input.) The end of input is indicated by a line containing a single 0. You may assume that no odometer reading will contain the digit 3 and 8.
 

 

Output
  Each line of input will produce exactly one line of output, which will contain: the odometer reading from the input, a colon, one blank space, and the actual number of miles traveled by the car.
 

 

Sample Input
15 2005 250 1500 999999 0
 

 

Sample Output
15: 12 2005: 1028 250: 160 1500: 768 999999: 262143
 

 

Source
 

 

Recommend
liuyiding
 
 
 
因为没有3和8,所以我们把一个数当作8(10-2)进制来看,因此,在这个输入的8进制数中,每一位的数上,9就看作是7,4、5、6、7
就当作3、4、5、6来看待,而3和8就当作0来看待,因此,当我们把这个八进制数转换成十进制数的时候,他就是我们所要求的结果了。
 
 
code:
1 #include
2 using namespace std; 3 4 int a[10]={
0,1,2,0,3,4,5,6,0,7}; 5 6 int main() 7 { 8 int n,m; 9 int ans;10 int temp;11 while(~scanf("%d",&n),n)12 {13 ans=0;14 m=n;15 temp=1;16 while(n)17 {18 ans+=a[n%10]*temp;19 n/=10;20 temp*=8;21 }22 printf("%d: %d\n",m,ans);23 }24 return 0;25 }

转载地址:http://mipdl.baihongyu.com/

你可能感兴趣的文章
[Javascript] Fetch API
查看>>
[改善Java代码]不使用stop方法停止线程
查看>>
Spring Boot新模块devtools
查看>>
关于Android读取不同位置(drawable,asset,SDCard)的图片资源的总结
查看>>
HAProxy的三种不同类型配置方案
查看>>
Unity3d之截图
查看>>
Windows下的Jdk 1.7*安装并配置(图文详解)
查看>>
JS判断客户端是手机还是PC的2个代码(转)
查看>>
分布式服务框架设计和实现
查看>>
dispatchTouchEvent
查看>>
Zabbix-3.0.3实现微信(WeChat)告警
查看>>
ArcGIS for Desktop入门教程_第三章_Desktop软件安装 - ArcGIS知乎-新一代ArcGIS问答社区...
查看>>
解决客户端访问https报错
查看>>
PHPCMS列表循环序列号自增标签代码
查看>>
2016年第15本:微信营销与运营----策略、方法、技巧与实践
查看>>
HTML之Data URL(转)
查看>>
注解式控制器
查看>>
ASP.Net中实现上传过程中将文本文件转换成PDF的方法
查看>>
maven The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path错误
查看>>
【数据库】数据库的并发问题与锁机制
查看>>