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. WmS具体解释(二)之怎样理解Window和窗体的关系?基于Android7.0源代码

    上篇博客(WmS具体解释(一)之token究竟是什么?基于Android7.0源代码)中我们简要介绍了token的作用,这里涉及到的概念非常多,当中出现频率最高的要数Window和窗体这一对搭档了,那 ...

  2. Chrome 主页被篡改

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

  3. matlab std函数 用法及实例

    MATLAB常常用到std函数来进行标准差计算,下面我就通过实例介绍一下 matlab std函数怎么用. 1. std函数是用来计算标准偏差的一个函数,由于其有不同的参数,我们就用下面的例子进行介绍 ...

  4. FileZilla等软件搭建ftp服务器

    一.常用的几款ftp服务器软件介绍 1.1 Server-U Serv-U是一种被广泛运用的FTP服务器端软件,支持3x/9x/ME/NT/2K/2000/xp等全Windows系列.可以设定多个FT ...

  5. SimpleDraweeView 设置圆角不生效问题

    采用的是xml配置 roundedCornerRadius 参数方法 adverPic.setImageURI("http://xx.xx.xx.xx/123.jpg"); 设置c ...

  6. 自然语言交流系统 phxnet团队 创新实训 项目博客 (十)

      关于本项目中使用到的庖丁分词的总结:   Paoding 详细介绍 庖丁中文分词库是一个使用Java开发的,可结合到Lucene应用中的,为互联网.企业内部网使用的中文搜索引擎分词组件.Paodi ...

  7. 《FPGA全程进阶---实战演练》第四章之实验平台软硬件使用简介

    本章主要是讲解读者在进行FPGA逻辑设计之前的准备工作,需要下载Quartus II软件和 Modelsim 软件,一个是用来进行FPGA逻辑设计,一个是用来对逻辑进行理论分析与验证. 1.1 qua ...

  8. ABAP--如何创建自定义打印条码

    ABAP--如何创建自定义打印条码 BARCODE in Smartforms: How to create customize BARCODE for Smartforms. 1 Introduct ...

  9. VC6下OpenGL 开发环境的构建外加一个简单的二维网络棋盘绘制示例

    一.安装GLUT 工具包 GLUT 不是OpenGL 所必须的,但它会给我们的学习带来一定的方便,推荐安装. Windows 环境下的GLUT 本地下载地址:glut-install.zip(大小约为 ...

  10. 第三百三十四节,web爬虫讲解2—Scrapy框架爬虫—Scrapy爬取百度新闻,爬取Ajax动态生成的信息

    第三百三十四节,web爬虫讲解2—Scrapy框架爬虫—Scrapy爬取百度新闻,爬取Ajax动态生成的信息 crapy爬取百度新闻,爬取Ajax动态生成的信息,抓取百度新闻首页的新闻rul地址 有多 ...