sicily 1240. Faulty Odometer
来源:互联网 发布:重装系统提示网络电缆 编辑:程序博客网 时间:2024/06/05 10:41
1240. Faulty Odometer
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
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
131520032005239250139915009999990
Sample Output
13: 1215: 132003: 14612005: 1462239: 197250: 1981399: 10521500: 1053999999: 531440
这道题用9进制可以水过,从左往右推就好,记得如果当前位数大于等于4就要减去1。
#include <iostream>#include <string>#include <cstdio> using namespace std;int main(){string num;while(cin>>num&&num!="0"){int ans=0;for(int i=0;i<num.length();i++){ans*=9;if(num[i]>'4')ans--;ans+=num[i]-'0';}printf("%s: %d\n",num.c_str(),ans);}}
#include <bits/stdc++.h>using namespace std;int dp[10][12];void init(){for(int i=0;i<=9;i++)dp[i][1]=(i==4);for(int i=2;i<=10;i++){for(int j=0;j<=9;j++){if(j!=4){dp[j][i]=0;for(int k=0;k<=9;k++)dp[j][i]+=dp[k][i-1];}else if(j==4){dp[j][i]=pow(10,i-1);}}}}int len(int number){int countt=0;while(number){number/=10;countt++;}return countt;}int main(){int number;init();//先预处理 while(scanf("%d",&number)&&number){int length=len(number);int tmp=number+1;int ans=0;while(tmp){int cur=tmp/pow(10,length-1);tmp=tmp-cur*pow(10,length-1);for(int i=0;i<cur;i++)ans+=dp[i][length];if(cur==4){ans+=tmp;break;}length--;}printf("%d: %d\n",number,number-ans);}}
- Sicily 1240. Faulty Odometer
- Sicily 1240. Faulty Odometer
- sicily 1240. Faulty Odometer
- sicily 1240. Faulty Odometer
- sicily 1240. Faulty Odometer 有例子说明
- sicily 1240 Faulty Odometer
- sicily 1780 Faulty Odometer Again
- Sicily 1780. Faulty Odometer Again
- Sicily 1240. Faulty Odometer | 进制理解及转换
- 1240.Faulty Odometer
- Faulty Odometer
- Faulty Odometer
- Faulty Odometer
- Faulty Odometer
- Faulty Odometer
- Faulty Odometer
- poj 2719 Faulty Odometer
- [POJ]2719 Faulty Odometer
- sublime text2编写html时如何快速地在指定浏览器中预览
- 配置minicom
- 有时候人活着就是累
- Android多媒体开发【10】-- android中OpenMax的实现【1】整体框架
- 几个有意思的运维编程题
- sicily 1240. Faulty Odometer
- Navicat
- jquery 获取相应元素
- plsql
- contest: Codeforces Round #301 (Div. 2), problem: (A) Combination Lock
- SAP制造业成本核算流程
- 错误:Failed to initialize Monitor Thread: Unable to establish loopback connection
- ubuntu12.04下使用minicom下载文件到ARM开发板
- 通用于Activity管理和应用程序退出