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 3 to the digit 5, always skipping over the digit 4. This defect shows up in all positions (the one's, the ten's, the hundred's, etc.). For example, if the odometer displays 15339 and the car travels one mile, odometer reading changes to 15350 (instead of 15340).

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 4.

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

13
15
2003
2005
239
250
1399
1500
999999
0

Sample Output

13: 12
15: 13
2003: 1461
2005: 1462
239: 197
250: 198
1399: 1052
1500: 1053
999999: 531440

Source

 
对于每个位来说,3等于是不存在的所以说一个位上如果是4,那么他其实是3,如果是5,其实是4,而且每个位只剩下9个数字来表示大小,那不就是九进制吗,所以从低位开始,如果一个位的数字大于3,就减1,然后按九进制来换算。
c++代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define MAX 0
#define inf 0x3f3f3f3f
using namespace std;
int n;
int main() {
while(~scanf("%d",&n) && n) {
int r = ,w = n,mi = ;
while(w) {
int d = w % ;
if(d > )d --;
r += d * mi;
w /= ;
mi *= ;
}
printf("%d: %d\n",n,r);
}
return ;
}

python代码:

while (True):
a = int(input())
if a == 0:
break
wa = a
ra = 0
mi = 1
while a != 0 :
d = a % 10
if d > 3 :
d -= 1
ra += d * mi
a = int(a / 10)
mi *= 9
print("%d: %d"%(wa,ra))

最新文章

  1. runtime
  2. Jstat PID not found
  3. 烂泥:mysql数据库使用的基本命令
  4. Android学习系列(43)--使用事件总线框架EventBus和Otto
  5. 为ssh增加选项
  6. 1415-2个人项目Individual Project
  7. CentOS 6.5 安装CodeBlocks
  8. Android-Activity生命周期从onStart直接到onStop
  9. Activity声明周期容易出现的问题
  10. node-canvas
  11. Mysql基础知识整
  12. 个人-GIT使用方法
  13. 使用PowerDesigner对NAME和COMMENT互相转换
  14. HTTP协议以及HTTP2.0/1.1/1.0区别
  15. python---数据类型---列表
  16. 【题解】Luogu P3674 小清新人渣的本愿
  17. 迭代(遍历)时候不可以使用集合的remove和add方法,但可使用Java迭代器的remove和add方法
  18. xftp5和xshell的使用
  19. JSONObject使用方法详解
  20. ThinkPHP 3.1,3.2中对IN和BETWEEN正则匹配不当导致的一个SQLi

热门文章

  1. WikiCFP--A Wiki for Calls For Papers
  2. java 动态实现接口
  3. Java中的Enum的继承
  4. 小tip: DOM appendHTML实现及insertAdjacentHTML
  5. 开源项目WebImageView载入图片
  6. cacti 安装和组件添加
  7. 【转】android 签名验证防止重打包
  8. ios -- 极光推送《2》--极光推送消息推送成功,但是手机收不到的解决方法
  9. Fragment 懒加载
  10. 一种流量成本节省60%以上的手机直播微信直播H5直播幼儿园直播方案