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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • JUnitParams参数化单元测试使用详解[通俗易懂]

    JUnitParams参数化单元测试使用详解[通俗易懂]JUnitParams(github地址:https://github.com/Pragmatists/JUnitParams)作为一个开源的单元测试框架,提供了参数化测试,Coder不需要通过构造器来设置参数,JUnitParams可以由测试方法提供参数,减少了代码量。接下来咱们就一探究竟。

    2022年6月17日
    42
  • 导航栏滚动渐变效果 html+css+js

    导航栏滚动渐变效果 html+css+js先看效果:实现:1.定义导航栏的文字标签:<divclass=”tou”><sapnclass=”logo”>北极光。</sapn><ulclass=”biao”><li><ahref=”#”><ahref=”#”>主页</a></li><li><ahref=”#”>个人简介</

    2022年5月8日
    40
  • python类型转换astype时间_python dataframe astype 字段类型转换方法

    python类型转换astype时间_python dataframe astype 字段类型转换方法使用astype实现dataframe字段类型转换#-*-coding:UTF-8-*-importpandasaspddf=pd.DataFrame([{‘col1′:’a’,’col2′:’1′},{‘col1′:’b’,’col2′:’2′}])printdf.dtypesdf[‘col2’]=df[‘col2’].astype(‘int’)print’–…

    2022年6月5日
    47
  • 几种ARM编译器及IDE开发环境[通俗易懂]

    几种ARM编译器及IDE开发环境[通俗易懂]ARM应用软件的开发工具根据功能的不同,分别有编译软件、汇编软件、链接软件、调试软件、嵌入式实时操作系统、函数库、评估板、JTAG仿真器、在线仿真器等,目前世界上约有四十多家公司提供以上不同类别的产品。  用户选用ARM处理器开发嵌入式系统时,选择合适的开发工具可以加快开发进度,节省开发成本。因此一套含有编辑软件、编译软件、汇编软件、链接软件、调试软件、工程管理及函数库的集成开发环境(IDE…

    2022年6月1日
    168
  • Android ConstraintLayout布局详解[通俗易懂]

    Android ConstraintLayout布局详解[通俗易懂]前言之前在使用AndroidStudio新建项目的时候,发现MainActivity的默认布局从RelativeLayout变成了ConstraintLayout。当时就对这个ConstraintLayout很好奇,就研究了一下。发觉确实很强大,在此做个总结。ConstraintLayout定义什么是ConstraintLayout呢?ConstraintLayout是Google在2016年的

    2022年5月5日
    87
  • 实际项目中如何使用Git做分支管理「建议收藏」

    实际项目中如何使用Git做分支管理「建议收藏」记得刚工作的时候根本不知道什么是版本管理工具,有一次和别人聊天,人家问你们公司代码用什么版本管理工具?我说啥是版本管理工具,我们一般用U盘拷贝,然后人家就顾左右而言他了。后来我知道了有个东西叫,后来又知道了还有个东西叫。所以说刚毕业的同学一定要优先进入专业的大公司,就像年轻时候应该去大城市闯两年一样,眼界以及你遇到的牛人会大大加快你以后成功的进程。本文主要是介绍一种在具体实践中使用Git来管理项目开发的一种成功的方式,其实主要思想来源于这篇文章Asuccessful…

    2022年10月1日
    6

发表回复

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

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