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



  • 相关阅读:
    relative 和 absolute 定位关系
    基于Linux的Samba开源共享解决方案测试(四)
    基于Linux的Samba开源共享解决方案测试(三)
    基于Linux的Samba开源共享解决方案测试(二)
    基于Linux的Samba开源共享解决方案测试(一)
    创建文件测试
    RHEL6.x查看网卡槽位对应设备文件及路径
    linux I/O优化 磁盘读写参数设置
    20个Linux服务器性能调优技巧
    Linux文件读写机制及优化方式
  • 原文地址:https://www.cnblogs.com/jhcelue/p/6979247.html
Copyright © 2011-2022 走看看