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



  • 相关阅读:
    android 生命周期图
    c++中 箭头> 双冒号:: 点号.操作符区别
    Blocks 笔记
    使用AVAudioRecorder 录音
    音频输入大小变化图
    【Linux】本机与服务器文件互传、Linux服务器文件上传下载
    【Oracle】Oracle解锁、Oracle锁表处理
    使用three.js创建3D机房模型分享一
    WPF下递归生成树形数据绑定到TreeView上
    (转载)C++抽象工厂模式(大话设计模式)
  • 原文地址:https://www.cnblogs.com/jhcelue/p/6979247.html
Copyright © 2011-2022 走看看