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

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
题解:油表坏了,遇到4就变成5,其实就是一个九进制数,注意大于4的要减一,我却吓模拟了半天。。。
代码:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath> using namespace std;
int *getary(int N){
int a[];
int *b;
b = (int *)malloc(sizeof(int) * );
memset(a, , sizeof(a));
int i = ;
while(N){
a[i ++] = N % ;
N /= ;
}
b[] = i;
for(int j = ; j <= i; j++){
b[j] = a[i - j];
}
return b;
} int main(){ int N;
while((scanf("%d", &N)), N){
int *a = getary(N); int temp = ;
for(int i = ; i <= a[]; i++){
if(a[i] > ){
a[i] --;
}
temp = temp * + a[i];
}
printf("%d: %d\n", N, temp);
} return ;
}
												

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. hdu 4278 Faulty Odometer(进制转换)

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

  3. [转]as3 算法实例【输出1 到最大的N 位数 题目:输入数字n,按顺序输出从1 最大的n 位10 进制数。比如输入3,则输出1、2、3 一直到最大的3 位数即999。】

    思路:如果我们在数字前面补0的话,就会发现n位所有10进制数其实就是n个从0到9的全排列.也就是说,我们把数字的每一位都从0到9排列一遍,就得到了所有的10进制数. /** *ch 存放数字 *n n ...

  4. 1813. M进制数问题

    1813. M进制数问题 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description 试用 C++的类来表示一般进制数. 给定 2 ...

  5. CF459C Pashmak and Buses (构造d位k进制数

    C - Pashmak and Buses Codeforces Round #261 (Div. 2) C. Pashmak and Buses time limit per test 1 seco ...

  6. [codevs1157]2^k进制数

    [codevs1157]2k进制数 试题描述 设r是个2k 进制数,并满足以下条件: (1)r至少是个2位的2k 进制数. (2)作为2k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. ...

  7. noip2006 2^k进制数

    设r是个2k进制数,并满足以下条件: (1)r至少是个2位的2k进制数. (2)作为2k进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进制数q后,则q的总位数不超过w ...

  8. c++描述将一个2进制数转化成10进制数(用到初始化栈,进栈,入栈)

    /* c++描述将2进制数转化成10进制数 问题,1.初始化栈后,用new,不知道delete是否要再写一个函数释放内存, 还是在哪里可以加上delete 2.如果栈满了,我要分配多点空间,我想的办法 ...

  9. 关于不同进制数之间转换的数学推导【Written By KillerLegend】

    关于不同进制数之间转换的数学推导 涉及范围:正整数范围内二进制(Binary),八进制(Octonary),十进制(Decimal),十六进制(hexadecimal)之间的转换 数的进制有多种,比如 ...

随机推荐

  1. filezilla server老提示connect server

    地址设置成127.0.0.1即可 端口14147 密码为空(也可能是string未测试) 上次登录的默认路径:C:\Users\admin\AppData\Roaming\FileZilla Serv ...

  2. Chrome 主页被篡改

    尝试恢复设置.重装chrome.改注册表均无果.最后意外发现解决方法无比简单:删掉桌面上的chrome图标,打开安装文件夹找到chrome.exe,随便改成什么名字.exe,比如baiduwcnm,重 ...

  3. onClickRow 事件

    onClickRow: function (rowIndex, rowData) {                        dgonClickRow(rowData.oldCityCode,r ...

  4. Java线程状态及 wait、sleep、join、interrupt、yield等的区别

    Java中的线程状态(详见Java线程状态及转换-MarchOn): wait:Object类的实例方法,释放CPU执行权,进入等待状态,直到  被中断.被拥有该对象锁的线程唤醒(notify或not ...

  5. USB2.0学习笔记连载(五):EZ-USB重要寄存器的配置

    本篇博客主要讲解EZ-USB一些重要寄存器的配置,首先对于本篇博客所讲的内容,读者应该到官网上去下载相关的手册,其中包括<EZ-USB Technical Reference Manual> ...

  6. 技能UP:SAP OBYC自动记账的实例说明(含value String应用说明)

    一. 自动过账原理 在MM模块的许多操作都能实现在FI模块自动过账,如PO收货.发票验证(LIV).工单发料.向生产车间发料等等.不用说,一定需要在IMG中进行配置才可以实现自动处理.但SAP实现的这 ...

  7. 第三百五十九节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)介绍以及安装

    第三百五十九节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)介绍以及安装 elasticsearch(搜索引擎)介绍 ElasticSearch是一个基于 ...

  8. 关于eclipse导工程或移植工程常碰到的错误汇总

      在开发过程中,eclipse是使用得最多的IDE,但由于其开源且免费的性质决定了其不然有很多的BUG,在项目很赶的时期碰到某些很恶的错误很浪费时间,也很让人郁闷,现我总结一下我碰到的错误并总结下对 ...

  9. EasyUI的combobox组件Chrome浏览器不兼容问题解决办法

    EasyUI版本:jQuery EasyUI 1.4.1 Chrome浏览器版本:41.0.2272.101 m 问题描述 在Chrome浏览器下,下拉框选择选项之后,选择的值在下拉框中不显示,重新选 ...

  10. zookeeper ACL使用

    生产环境中,经常会有多个项目使用zookeeper,例如多个hbase集群.每个项目搭建一套独立的zookeeper,无论从机器成本,还是运维成本,都是一笔额外的开销. 然而多项目,多集群共用zook ...