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))

poj 2719 Faulty Odometer的更多相关文章

  1. HDU 4278 Faulty Odometer 8进制转10进制

    Faulty Odometer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  2. Faulty Odometer(九进制数)

    Faulty Odometer Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9301   Accepted: 5759 D ...

  3. sicily 1240. Faulty Odometer

    Description You are given a car odometer which displays the miles traveled as an integer. The odomet ...

  4. hdu 4278 Faulty Odometer

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4278 #include<cstdio> #include<cstring> # ...

  5. POJ 2719

    #include<iostream> #include<stdio.h> using namespace std; ]; int _pow(int m,int n); int ...

  6. hdu 4278 Faulty Odometer(进制转换)

    十进制转八进制的变形: #include<stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF& ...

  7. C语言程序设计100例之(25):确定进制

    例25    确定进制 问题描述 6*9 = 42 对于十进制来说是错误的,但是对于13进制来说是正确的.即 6(13)* 9(13)= 42(13),因为,在十三进制中,42 = 4 * 13 + ...

  8. [GodLove]Wine93 Tarining Round #8

    比赛链接: http://vjudge.net/contest/view.action?cid=47644#overview 比赛来源: 2012 ACM/ICPC Asia Regional Tia ...

  9. HDU4278

    Faulty Odometer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

随机推荐

  1. 【深入JAVA EE】Spring配置文件解析

    在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 一.Spring头信息 Spring配置文件的头部信息通常是固定不变的.但每个标 ...

  2. Unable to save settings: Failed to save settings. Please restart PyCharm解决

    将工程的.ideas目录删掉,重启pycharm即可.

  3. linux下proc里关于磁盘性能的参数(转)

    我们在磁盘写操作持续繁忙的服务器上曾经碰到一个特殊的性能问题.每隔 30 秒,服务器就会遇到磁盘写活动高峰,导致请求处理延迟非常大(超过3秒).后来上网查了一下资料,通过调整内核参数,将写活动的高峰分 ...

  4. jquery Jsonp的使用

    <script type="text/javascript"> $(function(){ $.ajax({ url:"test", jsonpCa ...

  5. AWS:4.VPC

    主要介绍 1.Amazon混合云 2.将EC2加入VPC 3.VPC经典场景 4.VPC安全保障 Amazon混合云 : 在公有云的基础上创建私有云 VPC概念 VPC(VPC Virtual Pri ...

  6. 小程序的生命周期 launchApp

    https://developers.weixin.qq.com/miniprogram/dev/api/launchApp.html?search-key=生命周期 launchApp(OBJECT ...

  7. 如果数据需要被多个应用程序消费的话,推荐使用 Kafka,如果数据只是面向 Hadoop 的,可以使用 Flume

    https://www.ibm.com/developerworks/cn/opensource/os-cn-kafka/index.html Kafka 与 Flume 很多功能确实是重复的.以下是 ...

  8. CF148D. Bag of mice(概率DP)

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. VIM中使用tab键自动完成(vim tab键自动补全 )插件supertab

    supertab.vmb 这个插件好好用, Tab自动补全 http://www.vim.org/scripts/script.php?script_id=1643 安装步骤: 1.下载 supert ...

  10. API的理解和使用——集合

    集合类型的命令及时间复杂度  区间 命令 功能 时间复杂度  集合内 sadd key element [element ... ]  添加元素 O(k),k是元素个数 srem key elemen ...