zoukankan      html  css  js  c++  java
  • 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 integer. The odometer has a defect, however: it proceeds from the digit 2 to the digit 4 and from the digit 7 to the digit 9, always skipping over the digit 3 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 15229 and the car travels one mile, odometer reading changes to 15240 (instead of 15230).
     

    Input
      Each line of input contains a positive integer in the range 1..999999999 which represents an odometer reading. (Leading zeros will not appear in the input.) The end of input is indicated by a line containing a single 0. You may assume that no odometer reading will contain the digit 3 and 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
    15 2005 250 1500 999999 0
     

    Sample Output
    15: 12 2005: 1028 250: 160 1500: 768 999999: 262143
     


    题意:从1数到10,会跳过3和8。给你一个数,求这个数原来的值。

    题解:4被当成3用,5 6 7则代表4,5,6,9代表8,所以这类似8进制数。数值处理下转换成10进制就是原来的值。


    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<cstdio>
    #define N 5005
    #define ll long long
    
    using namespace std;
    
    int a[]= {0,1,2,0,3,4,5,6,0,7,0};
    ll k;
    
    int main() {
        //freopen("test.in","r",stdin);
        while(~scanf("%I64d",&k)&&k) {
            int num[10];
            int l=0;
            ll kk=k;
            while(k) {
                num[l++]=k%10;
                k/=10;
            }
            ll p=1;
            ll ans=0;
            for(int i=0; i<l; i++) {
                ans+=a[num[i]]*p;
                p*=8;
            }
            printf("%I64d: %I64d
    ",kk,ans);
        }
        return 0;
    }
    



  • 相关阅读:
    css 正方体
    鼠标放上去,不同的cursor光标类型
    文件上传用到的函数 20150205
    PHP常用正则表达式汇总
    代码练习之 登陆 PHP会话控制 session cookie
    正则表达式全部符号解释
    字典转模型
    Day11 TableView
    Day10
    Day9
  • 原文地址:https://www.cnblogs.com/jhcelue/p/6979247.html
Copyright © 2011-2022 走看看