hdu2544_GB4278

hdu2544_GB4278HDU 4278 Faulty Odometer

大家好,又见面了,我是你们的朋友全栈君。

Faulty Odometer

http://acm.hdu.edu.cn/showproblem.php?pid=4278

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 725    Accepted Submission(s): 512

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

 
Source
 
Recommend
liuyiding
 
 
类似于8进制转化为10进制
 
#include<stdio.h>

int num[20],cnt;

void change(int x){
    cnt=0;
    while(x){
        num[cnt++]=x%10;
        x/=10;
    }
    for(int i=0;i<cnt;i++)
        if(num[i]>=9)
            num[i]-=2;
        else if(num[i]>=4)
            num[i]-=1;
}

int main(){
    int n;
    while(scanf("%d",&n) && n){
        int ans=0;
        change(n);
        for(int i=cnt-1;i>=0;i--)
            ans=ans*8+num[i];
        printf("%d: %d\n",n,ans);
    }
    return 0;
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/107096.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • matlab做kmo检验的代码,急求 KMO测度和Bartlett 的球形度检验的计算原公式[通俗易懂]

    matlab做kmo检验的代码,急求 KMO测度和Bartlett 的球形度检验的计算原公式[通俗易懂]1、关于KMO公式,您从如下matlab源程序代码中不难得出,我已经用Excel就计算出来了,跟SPSS的计算结果完全一致。iX=inv(X);%X是原始数据的相关系数矩阵R,而inv表示求X的逆矩阵iXS2=diag(diag((iX.^-1)));%将iX的对角线的元素取倒数,其余元素都变为0,得到矩阵S2AIS=S2*iX*S2;%anti-image…

    2022年6月29日
    83
  • 工商银行近20年实时大数据平台建设历程「建议收藏」

    工商银行近20年实时大数据平台建设历程「建议收藏」全文共4000个字,建议阅读10分钟一、工行实时大数据平台建设历程工商银行从2002年开始建设数据集市,当时主要使用Oracle类单机版的关系型数据库。随着数据量不断增加,开始引入TD、ED等国外高端一体机。2014年工行正式基于Hadoop技术建设了大数据平台,在其之上构建了企业级数据湖及数据仓库。2017年,随着AI技术的兴起,又开始建设机器学…

    2022年6月7日
    43
  • java基础API

    java基础APIJava常用类库1.API(1)ApplicationProgrammingInterface,应用程序接口。是一些预先定义的类和接口,或指软件系统不同组成部分衔接的约定。(2)API说明文档API文档查看方式:第一步选择包,第二步,选择类或接口,第三步查看类和接口的使用说明,右边的区域。右边的区域分为五块,分别为类的定义和功能介绍、属性的介绍、构造器的介绍、构造器的介绍、方法的列表、每个方法的使用详细说明。2、java.lang包(1)这是我们api中最基础的一个包(2)该包下面的

    2022年7月9日
    20
  • JVM学习1

    JVM学习1

    2021年11月12日
    44
  • 2020/4/1微信小程序笔记

    2020/4/1微信小程序笔记1.微信小程序的登录流程 通过wx.login()获取登录凭证code 通过button组件的open-type=”getUserInfo”, 获取用户信息 将获取到的登录凭证和用户信息传递到自己的服务器 在自己的服务器上将登录凭证发送到微信的服务器上换取openid和session_key …

    2022年8月18日
    8
  • webstorm2019激活码【中文破解版】

    (webstorm2019激活码)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html23…

    2022年3月29日
    79

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号