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\n",kk,ans);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-14 11:06:50

Hdu 4278 Faulty Odometer(8进制转10进制)的相关文章

java 16进制转换10进制

public static String toHexString2(byte[] b) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < b.length; ++i) { buffer.append(toHexString2(b[i])); } return buffer.toString(); } public static String toHexString2(byte b) { char[] buffer =

2进制,8进制,16进制转10进制的自定义函数

1.2进制转10进制自定义函数: function DecToInt(temp:string):integer; //2进制转10进制var  i,j  : Integer;begin  result := 0;  j   := Length(temp);  //取得字符串长度:  for I := 0 to Length(temp)-1 do  begin    result := result+strtoint(Copy(temp,j,1))*Trunc(power(2,I));  //Tr

Java 10进制转2、8、16进制转换 / 2、8、16进制转10进制转换

public static void main(String[] args) { int i = 10; System.out.println("***********10进制转换2进制.8进制.16进制************"); System.out.println(Integer.toBinaryString(i)); // 10转换2进制 System.out.println(Integer.toOctalString(i)); // 10转换8进制 System.out.p

16进制与10进制

16进制 0 1 2 3 4 5 6 7 8 9 a b c d e f. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 1 2(16进制中的10 进制表象,进位后,前边一位)10进制 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20我们的计算机中一般都以16进制保存.我们用的时间就是这种60进制中的10进制表象.

PHP进制转换[实现2、8、16、36、64进制至10进制相互转换]

自己写了一个PHP进制转换程序,一个类吧,第一次写这个东东,写这个东东,在处理文本文件时能用得到. 可以实现: 10进制转换2.8.16.36.62进制2.8.16.36.62进制转换10进制 有点要注意下,2.8.16进制转换时,使用的是系统的自己的函数. 所以,不管怎么高精度转换值可能大于2147483646. 另外, 32进制低精转换,最大值:2147483646: 32进制高精转换,最大值:77309411327: 64进制高精转换,最大值:133143986175. jinzhi.ph

第一个python小程序,2进制转10进制

#Bin to Dec #my first python programe n = c = itm = 0 a = raw_input('please input Binary number:\n') for n in range(0,len(a)):    b = a[n:n+1] #   print 'n is', n #   print 'b is',b #   print 'len',len(a[n:])       if b == '1':    c = 2**(len(a[n:])-

10进制转16进制,16进制转10进制,随机出一个6位十六进制颜色值

方案一: var num16 = "ffffff";var num10 = parseInt(num16,16);//16进制转10进制console.log(num10) // 16777215 var colorNum = Math.round(Math.random()*num10).toString(16);colorNum = ("000000"+colorNum).slice(-6)console.log("#"+colorNum)

Delphi XE2 16进制转10进制《LceMeaning》

以下在编写IC卡项目时出现卡号转换错误时的解决方法,在XE2下测试正常.================================================ uses math; function HexToDec(Hex : string) : string; var i : integer; res : real; len : integer; begin len := length(Trim(Hex)); for i := 1 to len do begin case Hex[

16进制转10进制和2进制

/** * 16进制转10进制 * * @param str * @return */ public static String sixteenToTen(String str) { int ten = Integer.parseInt(str, 16); String result = String.valueOf(ten); return result; } /** * 16进制转2进制 * @param str * @return */ public static String hexSt