Sicily 1780. Faulty Odometer Again

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 1 to the digit 3, from the digit 4 to the digit 6 and from the digit 7 to the digit 9, always skipping over the digit
2, 5 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 13419 and the car travels one mile, odometer reading changes to 13430 (instead of 13420).

Input

The first line of input contains a positive integer T, represents the number of test cases. Then T lines follow. Each line contains a positive integer in the range 1..999999999 which
represents an odometer reading. (Leading zeros will not appear in the input.) You may assume that no odometer reading will contain the digit 2, 5 or 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

 Copy sample input to clipboard

6
1
3
4
6
7
999999999

Sample Output

1: 1
3: 2
4: 3
6: 4
7: 5
999999999: 40353606
// Problem#: 1780
// Submission#: 3708249
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<cstdio>
#include<cctype>
#include<iomanip>
#include<vector>
#include<cstring>
#include<string>
#include<fstream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int check(int n){
    if(n<2)
        return 0;
    else if(n<5)
        return 1;
    else if(n<8)
        return 2;
    else
        return 3;
}
int main(){
    int n;
    cin>>n;
    int s[10]={0,3,51,657,7599,83193,882351,9176457,94235199,959646393};
    while(n--){
       int t;
       cin>>t;
       int ans=0;
       int k=1,m=0;
       int tem=t;
       while(t){
            int tem=0;
            tem+=check(t%10);
            t/=10;
            tem+=t*3;
            tem*=(k-s[m]);
            ans+=tem;
            k*=10;
            m++;
        }
        cout<<tem<<": "<<tem-ans<<endl;
    }
}                                 

时间: 2024-10-24 23:17:16

Sicily 1780. Faulty Odometer Again的相关文章

sicily 1240. Faulty Odometer

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 on

Hdu 4278 Faulty Odometer(8进制转10进制)

Faulty Odometer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1664    Accepted Submission(s): 1146 Problem Description You are given a car odometer which displays the miles traveled as an int

poj 2719 Faulty Odometer

题意: 有辆车的里程表坏了,会跳过数字4,比如 3 接下来直接到5,再比如39 - 50  13 -15 239-259 39999-50000(好吧,该换车了).如果车的里程表显示走了n公里,求实际走了多少. 打标找到了规律前10个少了1, 100少了19, 1000少了19×9+100=271, 10000中少了271*9+1000 = 2439 ............. 规律很明显了吧!! 遇题多思考,像这种题,看到数据量就知道暴力是不可能的,所以就不需要再尝试了,浪费时间,尤其是在正式

HDU ACM 4278 Faulty Odometer 进制映射

分析:十进制映射到八进制后,如果跳过8到9,实际上只数了7次,如果跳过3到了4-7实际上只数了3-6次.对应关系如下. 0,1,2,3,4,5,6,7,8,9 0,1,2,-,3,4,5,6,-,7 #include<iostream> using namespace std; int main() { int a[10]={0,1,2,0,3,4,5,6,0,7},i; __int64 ans,k; char b[15]; while(gets(b) && b[0]!='0'

HDU4278 Faulty Odometer(进制转化问题)

题目大意:里程表会错过0 1 2 3 4 5 6 7 8 9中的 3 和 8 两个数字 也就是 正常的里程表显示0 1 2 3 4 5 6 7 8 9 坏掉的里程表只会显示 0 1 2 4 5 6 7 9 其实可以看做:0 1 2 3 4 5 6 7  即坏掉的里程表显示的是8进制的数字,只需先将显示的数字换成8进制数,在把8进制数字换位10进制数字就是答案. #include <iostream> #include <map> #include <sstream> #

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

(转)sicily题目分类

Sicily题目分类 ·         [数据结构/图论] 1310 Right-Heavy Tree   笛卡尔树相关,复杂度O(N)或O(NlogN). ·1426 Phone List         电话号码前缀检索,trie树相关. ·1443 Printer Queue      基本队列操作. ·1149 等价表达式         判断表达式是否等价(递归求解) ·1136 山海经             n长序列里求m次区间询问的最大连续子区间和.线段树/RMQ ·1252

HDU4278Faulty Odometer

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4278 Faulty Odometer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1154    Accepted Submission(s): 801 P

[GodLove]Wine93 Tarining Round #8

比赛链接: http://vjudge.net/contest/view.action?cid=47644#overview 比赛来源: 2012 ACM/ICPC Asia Regional Tianjin Online 果然我还是很受外界影响啊~~~这场打得好烂~~~ 155 / 175 Problem A HDU 4278 Faulty Odometer (水题, 简单的数位DP) 155 / 345 Problem B HDU 4279 Number  (打表找规律)   86 / 41