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. 回顾:maven配置和常用命令整理

    推荐两个库地址,开源中国的好像不好使了 阿里的仓库:http://maven.aliyun.com/nexus/content/groups/public/ 另一个:http://repo2.mave ...

  2. Drupal Nginx伪静态设置方法

    location ~ ^.*/files\/styles\/.*$ { access_log off; expires 45d; error_page @drupal; } location @dru ...

  3. 【jquery】jquery 自定义滚动条

    可以自由的给滚动条定义背景,上下按钮,当然不仅仅是颜色,连图片当背景也可以.支持鼠标滚轮,点击滚动条滚轴定位,上下按钮久按加速,兼容 ie,firefox,chrome. 调用方法: $(" ...

  4. jQuery(十一):jQuery的事件

    一.jQuery事件的分类 jQuery事件是对JavaScript事件的封装,常用事件分类如下: 1.基础事件 window事件. 鼠标事件. 键盘事件. 表单事件. 2.复合事件是多个事件的组合 ...

  5. ubuntu下IDEA配置tomcat报错Warning the selected directory is not a valid tomcat home

    产生这个问题的主要原因是文件夹权限问题. 可以修改文件夹权限或者更改tomcat文件目录所有者. 这里我直接变更tomcat文件夹所有者: sudo chown -R skh:skh tomcat-/ ...

  6. iptable 限制ip访问

    -- 查找所有规则iptables -L INPUT --line-numbers -- 删除一条规则iptables -D INPUT 11 (注意,这个11是行号,是iptables -L INP ...

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

    情感倾向可认为是主体对某一客体主观存在的内心喜恶,内在评价的一种倾向.它由两个方面来衡量:一个情感倾向方向,一个是情感倾向度. 情感倾向方向也称为情感极性.在微博中,可以理解为用户对某客体表达自身观点 ...

  8. 关于Unity中拖尾渲染器的使用

    拖尾渲染器 是一个组件,能够帮我们绘制出拖尾的效果. 就是跟在运动物体后面的东西,前进的过程中,末尾的不断消失,前面的不断生成,有一个长度.长度是以时间计算的,从末尾到头有多少秒的时间就是拖尾的长度. ...

  9. C++ 结构体和枚举

    共同体 共同体(union) 是一种数据格式, 它能够存储不同的数据类型, 但只能同时存储其中的一种类型.也就是说, 结构可以同时存储int.long 和 double, 共同体只能存储int.lon ...

  10. (笔记)AES加密在线计算工具

    AES加密在线计算工具: http://aes.online-domain-tools.com/