码迷,mamicode.com
首页 > 其他好文 > 详细

Sicily 1780. Faulty Odometer Again

时间:2015-04-28 16:16:02      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

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

Sicily 1780. Faulty Odometer Again

标签:

原文地址:http://blog.csdn.net/christophe123/article/details/45335671

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!