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;
    }
}                                 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值