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. Angular+Angular-Ui实现分页(代码更加简单,更加容易懂哦)

    前面写了个分页,但是个人认为只能玩玩,实际业务上的话代码太繁杂(笔者想走代码.性能精简化之路[不知道哪天才能成为高手~·YY一下无伤大雅]),逻辑上有点混乱.那么今天我们来看看另外一种只实现分页没有查 ...

  2. VS中单元测试用法

    using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTestProject1 { [Test ...

  3. U-Boot中关于TEXT_BASE,代码重定位,链接地址相关说明

    都知道U-BOOT分为两个阶段,第一阶段是(~/cpu/arm920t/start.S中)在FLASH上运行(一般情况 下),完成对硬件的初始化,包括看门狗,中断缓存等,并且负责把代码搬移到SDRAM ...

  4. IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯(一)

    IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯 前言 .net core 2.1已经正式发布了,signalr core1.0随之发布,是时候写个 ...

  5. 自定义一个处理图片的HttpHandler

    有时项目里我们必须将图片进行一定的操作,例如水印,下载等,为了方便和管理我们可以自定义一个HttpHander 来负责这些工作 后台: public class ImageHandler : IHtt ...

  6. 关于打开sdk下载不了的最优秀解决方式

    使用网站:  mirrors.neusoft.edu.cn  东北大学就可以

  7. 字符数组和strcpy

    已知strcpy函数的原型是char *strcpy(char *strDest, const char *strSrc);,其中strDest是目的字符串,strSrc是源字符串. (1)Write ...

  8. tps 与 事务平均响应时间关系对答(转)

    问者:每秒处理的事务数和事务的平均响应时间 怎么个关系,有关系吗 kaku21:举个例子:一个高速路 有10个入口,每个入口每秒钟只能进1辆车,请问1秒钟最多能进几辆车?? 问者:10 kaku21: ...

  9. 五个知识体系之-SQL语句大全

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  10. 实现RTSP摄像机进行网页直播和微信直播的技术方案:EasyNVR自动更新方法

    问题背景: 1.EasyNVR的用户越来越多,技术人员一一对应解答效率不高: 2.随着EasyNVR应用场景的不断增加,以及EasyNVR自身在技术上的不断优化,版本更新比较快: 3.由于开发人力有限 ...