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. 【转】15个最受欢迎的Python开源框架

    以下是伯乐在线从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框 ...

  2. backbone的对象继承实现

    通过原型链实现对象的继承,子类通过’__super__‘来访问父类的方法 // protoProps 子类的属性参数 // staticProps 静态属性 var extend = function ...

  3. Entity Framework应用:导航属性

    一.主键和外键 关系型数据库中的一条记录中有若干个属性,若其中某一个属性组是能唯一标识一条记录,该属性组就可以称为主键.例如: 学生版(学号.姓名.性别.班级) 其中每个学生的学号是唯一的,学号就是一 ...

  4. [spark 快速大数据分析读书笔记] 第一章 导论

    [序言] Spark 基于内存的基本类型 (primitive)为一些应用程序带来了 100 倍的性能提升.Spark 允许用户程序将数据加载到 集群内存中用于反复查询,非常适用于大数据和机器学习. ...

  5. 自然语言交流系统 phxnet团队 创新实训 个人博客 (十二)

    在本项目中关于天空盒子的使用的配置方法: 给场景添加天空盒  第二种方式   在菜单栏中选择:Edit->Render Setting,在保证不在选择场景中其它文件的前提下,Inspector面 ...

  6. USB学习笔记连载(十一):CY7C68013A的启动方式-EEPROM

       上述的应用笔记中有介绍FX2LP的启动选项,主要包括I2C启动和USB启动. 说白了I2C启动需要使用外部的EEPROM,USB启动,只是使用上位机控制软件将配置程序FX2LP中,不用EEPRO ...

  7. JAVA NIO 简单介绍

    Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:00000099 EndFragment:00918492 一:为什么要使用NIO技术        ...

  8. c数据结构第一个公式写程序计算给定多项式在给定点x处的值

    假设x=2,那么a的数组有几个, 那n就是根据索引来的 假设数组[, , , , ] n就是0, 1, 2,,3, 4 f = + ( + ( + ( + ()))) f = + ( + ( + ( ...

  9. SAP 金税接口代码 供参考

    程序可以通过抓取 客户 开票信息等 下载文本 导出 需要事先创建好几个structure zc0000sdt0016, zc0000sdt0017 REPORT zc0000sdr0016 NO ST ...

  10. e860. 列出组件绑定的键盘键

    This example demonstrates how to list all the key bindings in a component. Text components have an a ...