Sicily 1780. Faulty odometer Again

Source: Internet
Author: User
Tags creative commons attribution

Descriptionyou is given a car odometer which displays the miles traveled as an integer. The odometer have 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 and 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 13 420). Inputthe first line of input contains a positive integerT, represents the number of test cases. ThenTLines follow. Each line contains a positive integer in the range 1..999999999 which represents an odometer reading. (Leading zeros won't appear in the input.) Assume that no odometer reading would contain the digit 2, 5 or 8.OutputEach line of input would produce exactly one Line of output, which would 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
613467999999999
Sample Output
1:13:24:36:47:5999999999:40353606
problem#: 1780//submission#: 3708249//The source code is licensed under Creative Commons Attribution-noncommercial-sh Arealike 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.