Faulty Odometer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2231    Accepted Submission(s): 1537

Problem 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 2 to the digit 4 and from the digit 7 to the digit 9, always skipping over the digit 3 and 8. This defect shows up in all positions (the one's, the ten's, the hundred's, etc.). For example, if the odometer displays 15229 and the car travels one mile, odometer reading changes to 15240 (instead of 15230).

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 3 and 8.

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

15
2005
250
1500
999999
0

Sample Output

15: 12
2005: 1028
250: 160
1500: 768
999999: 262143

Source

2012 ACM/ICPC Asia Regional Tianjin Online

#include<stdio.h>
#include<string.h>
int main()
{int n,len,num,ba,i;char s[10];while(gets(s)!=NULL){if(strcmp(s,"0")==0)break;len=strlen(s);num=0;//字符串转换成数字for(i=0; i<len; i++){num=num*10+s[i]-'0';}//转换成八进制for(i=0; i<len; i++){if(s[i]>'8')//if(s[i]>=9)s[i]-=2;else if(s[i]>'3')//if(s[i]>=4)s[i]-=1;}ba=0;for(i=0;i<len;i++){ba=ba*8+s[i]-'0';}printf("%d: %d\n",num,ba);}
}

此题是将八进制转换成十进制,也可以理解为统计从1~n除去含有‘3’‘8’数字外所有的数字的个数。

A - Faulty Odometer相关推荐

  1. HDU-4278 Faulty Odometer 数学递推 || 八进制

    题意 这个里程表当走到3或8的时候就会跳过 给我们这个里程表上显示的数字 让我们求这个里程表的真实数据是多少 分析 由于 3 和 8 不存在 那么就相当于一个八进制数 但是这个八进制中3 是写作4 8 ...

  2. Soj题目分类 python代码)

    正值期末复习,刷点soj放松下 但想看看能不能在找点关于数据结构的题目来做一下. 在网上看到有不少人上传过那些关于部分SOJ题目的描述,但是说实话有些乱 不过我看到有个网页中包含的一个类似文档的东西, ...

  3. 初学者acm的练习题指南

    上机练习题参考题 忘了在哪找的啦~~希望对大家有帮助呦 <!--[if !supportLists]-->1.    <!--[endif]-->Programming Bas ...

  4. sicily题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

  5. [sicily]部分题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

  6. Sicily 题目分类

    依照自己水平挑着做→ →~~ 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 ...

  7. 编程题目分类(剪辑)

    1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代 ...

  8. 中大SICILY分类

    原文出处:http://linguifan2010.blog.163.com/blog/static/1315127442010102131322482/ ********************** ...

  9. html5 数字滚动选择器,Odometer使用JavaScript和CSS制作数字滑动效果

    Odometer是一个使用JavaScript和CSS技术,制作出数字上下滑动的动画效果插件,有点类似与我们的天然气的读数的动画效果,这个插件是轻量级的,压缩版本只有3kg,使用CSS3动画技术,所以 ...

  10. URAL 2081 Faulty dial

    题目: Faulty dial Pavel has not played ACM for ages, nor does he train teams, nor prepare problems. Th ...

最新文章

  1. python工程师面试题-朋友去面试Python工程师,又带回来几道基础题,Python面试题No10...
  2. Linux 使用记录
  3. Spring中Quartz的最精简的配置
  4. numpy的基本使用
  5. 首个JDK 10(18.3)发行候选版(内部版本43)展示了新的版本控制方案
  6. 数组中其余的排除_6.8 C++字符数组 | 输出a、b、c
  7. [转载] Java:简述Java中的自定义异常
  8. java xssf 字体样式_Apache POI字体/Fonts
  9. unity3d实现水果机(随机)跑马灯效果
  10. 指数基金的分类以及投资方法
  11. Chrome远程调试手机端UC浏览器
  12. Microsoft Excel 教程:如何在 Excel 中筛选唯一值或删除重复值?
  13. c#未能加载程序集oracle.dataaccess,未能加载文件或程序集“Oracle.DataAccess, Version=2.112.1.0...
  14. 5G系统——5G-GUTI、5G-TMSI、5G-S-TMSI、SUPI、SUCI
  15. Unsupervised Hyperspectral Mixed Noise Removal Via Spatial-Spectral Constrained Deep Image Prior
  16. Java练习之复数运算
  17. Ubuntu20.04|最新一版的深度学习基础环境安装指导
  18. 单片机:各类模块数据手册及其资源
  19. 通信2M传输基本知识
  20. 【R语言实验】聚类分析

热门文章

  1. 由计算机病毒引起的问题属于,多数情况下由计算机病毒程序引起的问题属于()故障。A.硬件B.软件C.操作D.电源...
  2. clang-format的使用
  3. Timesnet: Temporal 2d-variation modeling for general time series analysis
  4. win10系统还原点怎么设置
  5. vue中axios的post请求url自动带上本地ip解决方法
  6. Harvard (name and date) 论文引用格式
  7. 注册码系统V2的自动发卡功能使用流程
  8. 考拉nbsp;PASCALnbsp;解题报告
  9. INA230测量电压电流功率
  10. 高盛发布VR/AR研究报告