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