博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4278 Faulty Odometer【进制转换】
阅读量:6545 次
发布时间:2019-06-24

本文共 2214 字,大约阅读时间需要 7 分钟。

Faulty Odometer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2017    Accepted Submission(s): 1398

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
 

 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:            
 
比较明显的8进制转10进制的题目,只要处理一下因为跳过数字产生的误差就可以了。
#include #include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#define LOACL#define space " "using namespace std;typedef long long LL;//typedef __int64 Int;typedef pair
PAI;const int INF = 0x3f3f3f3f;const double ESP = 1e-5;const double PI = acos(-1.0);const int MOD = 1e9 + 7;const int MAXN = 50 + 10;int bit[MAXN];int main() { int N; while (scanf("%d", &N), N) { int cnt = 0; int t = N; while (N) { bit[cnt++] = N%10; N /= 10; } for (int i = 0; i < cnt; i++) { if (bit[i] > 3) bit[i]--; if (bit[i] == 8) bit[i]--; } int ans = 0; for (int i = 0; i < cnt; i++) { ans += bit[i]*pow(8, i); } printf("%d: %d\n", t, ans); } return 0;}

 

 

 

转载于:https://www.cnblogs.com/cniwoq/p/6770745.html

你可能感兴趣的文章
2016/10/09
查看>>
自定义HorizontalScrollView的scrollBar
查看>>
c++学习笔记和思考
查看>>
27.Docker集群部署
查看>>
DNS保存
查看>>
IOS 多线程02-pthread 、 NSThread 、GCD 、NSOperationQueue、NSRunLoop
查看>>
第一周冲刺第五天博客
查看>>
[LeetCode]Longest Increasing Path in a Matrix
查看>>
C++基础之适配器
查看>>
集合set-深入学习
查看>>
C#语言学习——面向对象的几大原则
查看>>
zk 常用资料整理(转)
查看>>
JavaScript 字符串操作
查看>>
Android中asset文件夹和raw文件夹区别
查看>>
Fuel 30 分钟快速安装openstack 分类: 软件插件学习 ...
查看>>
第二章家庭作业 2.78
查看>>
Android 下拉刷新上拉载入 多种应用场景 超级大放送(上)
查看>>
Risc-V指令集
查看>>
Python进阶04 函数的参数对应
查看>>
C语言结构体的“继承”
查看>>