Faulty Odometer
2015-09-14 00:16
274 查看
A - Faulty Odometer
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
4278
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
题意:
就是一个汽车的里程表其中3,8是不会出现的。如2+1!=3等于4。
思路:
一开始都不知道怎么做,认为是dp吧。结果一直不行。最后问了一下同学,才知道是十进制转八进制。
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
4278
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
题意:
就是一个汽车的里程表其中3,8是不会出现的。如2+1!=3等于4。
思路:
一开始都不知道怎么做,认为是dp吧。结果一直不行。最后问了一下同学,才知道是十进制转八进制。
#include<iostream> #include<algorithm> #include<cstring> #include<string> #include<cstdio> using namespace std; int fx(int n) { int k=1; while(n) { k*=8;n--; } return k; } int main() { int k,i,j,n; char s[15]; while(scanf("%s",&s)&&s[0]!='0') { n=0; for(i=0;s[i];++i){ n=n*10+s[i]-'0'; if(s[i]>'8') s[i]-=2; else if(s[i]>'3') s[i]-=1; }j=strlen(s)-1; for(i=0,k=0;s[i];++i) k+=(s[i]-'0')*fx(j-i); printf("%d: %d\n",n,k); } return 0; }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- 使用Lua来扩展C++程序的方法
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- C++ Custom Control控件向父窗体发送对应的消息
- C++中拷贝构造函数的应用详解